Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Split criteria

by arkturuz (Curate)
on Nov 05, 2008 at 09:45 UTC ( #721586=note: print w/ replies, xml ) Need Help??


in reply to Split criteria

You have an unfortunate field delimiter, so something like this might help:

while(<DATA>) { my $str = $_; $str =~ s/!,!/!:::!/g; my @parts = split(':::', $str); print join("==>", @parts), "\n"; }
Output:
!A001ST!==>!98!==>!1!==>!01/10/1999!==>!EUROPEENNE!==>!0!==>!EUR!==>!6 +!==>!7!==>!0!==>!98!==>!1! !A001ST!==>!AD,CD!==>!1!==>!20/05/2004!==>!ANDORRA!==>!0!==>!EUR,USD!= +=>!6!==>!7!==>!0!==>!AD!==>!1!


Comment on Re: Split criteria
Select or Download Code
Re^2: Split criteria
by JavaFan (Canon) on Nov 05, 2008 at 09:59 UTC
    That would break as soon as there's a field containing ':::'.
      Sure. It's not in the given data though.

        When trying to come up with a really unlikely temporary separator it's better to use something really unlikely to occur in the real data. Since perl can cope with strings with embedded nulls just fine s/!,!/!\0!/g would be a more robust option.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-23 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (209 votes), past polls