Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Reusing camel code

by gmax (Abbot)
on Dec 03, 2001 at 15:19 UTC ( #129064=note: print w/ replies, xml ) Need Help??


in reply to Re: Reusing camel code
in thread Reusing camel code

Thank you very much for your hints. I tested your code

for (split(/:/, $$pattern)) { $_ = 'S0' . $_ unless /^S/; $_ .= 'S0' unless /S\d+$/; print STDERR "pattern: $_\n"; my @pieces = split(/[SF](\d+)/, $_); foreach my $count (0..$#pieces) { print STDERR "$count -> [$pieces[$count]] "; } print STDERR "\n"; }
But I got an odd output. Split gives back some empty items
pattern: S51F11S0 0 -> [] 1 -> [51] 2 -> [] 3 -> [11] 4 -> [] 5 -> [0]
Changing split to match only /[SF]/ (your update suggestion) and adding a shift afterwards improves the output,
pattern: S51F11S0 0 -> [51] 1 -> [11] 2 -> [0]
leaving me with the second problem, i.e. that having an odd number of items in my array, splice(@,0,2) will give back an undefined second element.
Nothing catastrophic, but it is going to increase the number of necessary checks.
Even if it doesn't do what I need, though, this code of yours gives me some ideas that I can further develop.
As for the second hint:
tr/ //d; $camel .= $_;
yes, it looks much faster (not to mention smarter) than my code.
Ciao gmax


Comment on Re: Re: Reusing camel code
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-08-23 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls