Please help me understand this code...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NOTSomebody
    New Member
    • Jul 2008
    • 13

    Please help me understand this code...

    I am new to Perl and I have these codes but I am not quite understand the regular expression here. Can any1 please explain to me?

    Code:
    $csv = "test.csv";
    open(DAT, $csv) || die("Cannot Open File");
    
    while (<DAT>) {
        my @new  = ();
    
        push(@new, $+) while $_ =~ m{          #what does these means
            "([^\"\\]*(?:\\.[^\"\\]*)*)",?
               |  ([^,]+),?
               | ,
    		}gx;
    
        push(@new, undef) if substr($_, -1,1) eq ',';
    	   
    	my $string = format_string(@new);
    	my $query = qq{Insert into person_info VALUES ($string)};
        print $query, "\n"; 
    }  
    
     sub format_string {  
    		my $string; 
            foreach (@_) {
                if  (/[^\d]/) {          #what does these mean
                    $string .= qq{"$_",};
    			} else {
    				$string .= qq{$_,};
    			}
    		}
    		return substr($string, 0, -1); 
    	}
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    See your thread on Devshed.

    Comment

    Working...