Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://129064]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-01-21 05:55 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.