Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: regex pattern match

by reaper9187 (Scribe)
on Mar 29, 2013 at 09:41 UTC ( #1026116=note: print w/ replies, xml ) Need Help??


in reply to regex pattern match

Hi .. Thank you for the quick reply .. Is it somehow possible to do it without using any module...?? I've reached thus far with the code

$in_file = "test.txt"; $out_file = "testout.txt"; open (IN, "<$in_file") or die "Can't open $in_file: $!\n"; open (OUT, ">$out_file") or die "Can't open $out_file: $!\n"; while ( $line = <IN> ) { @fields = split /,/, $line; $line = join ",", $fields[0], @fields[1..5]; print OUT $line; print OUT "\n"; } close IN; close OUT; #read in output file and print to screen to confirm open (TEST, "<$out_file") or die "Can't open $out_file: $!\n"; while ( <TEST> ) { print; } close TEST;
There's only one problem bugging me .. How do i exclude the double quoted string from the pattern match in the split statement ..Once i am able to do that , the rest should be easy.. else it jus increases the amount of processing i need to do...


Comment on Re: regex pattern match
Download Code
Replies are listed 'Best First'.
Re^2: regex pattern match
by McA (Priest) on Mar 29, 2013 at 09:54 UTC

    Hi

    what do you think about the following:

    #strip LF from line chomp $line; # delete the very first and last " from line for ($line) { s/^\s*"//; s/"\s*$//; } # now split @fields = split /"\s*,\s*"/, $line; # now you should have the pieces I mentioned above

    McA

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026116]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-08-01 01:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls