Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Spliting a delimited string into variables

by Anonymous Monk
on Nov 28, 2013 at 14:49 UTC ( [id://1064841]=note: print w/replies, xml ) Need Help??


in reply to Re: Spliting a delimited string into variables
in thread Spliting a delimited string into variables

Hi,

One other simpler way to make it works is to use regex memory as follow.

my $line="371540|4/07/2011|08:03|11:03|2|Company Name (MAIN SITE)|DB P +URGE|" if ($line =~ /(\d+)\|([0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4})\|([0-9]{1,2}\: +[0-9]{2})\|([0-9]{1,2}\:[0-9]{2})\|(\d+)\|((?:\w+)\s\w+\s(?:\()?\w+\s +\w+\))\|(\w+(?:\s)?\w+)/ ) { $item1=$1; $item2=$2; ... $item7=$7 }

Note that the regexp has to be adapted. The parentheses captures their content.
First parenthese will be memorised as $1, Second parenthese will be memorised as $2 etc...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found