Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Regex Matching

by jeroenes (Priest)
on Jul 05, 2001 at 17:22 UTC ( #94092=note: print w/ replies, xml ) Need Help??


in reply to Regex Matching

The trick lies in the fact that you want to match any character, but that the dot looses its special meaning in the square brackets. See perlop and perlre. You could just replace the bracket stuff with a single dot.

I would prefer to use substr to get the data (untested, you get the idea mehopes):

my @lengths = qw/1 20 20 5/; #inside some looplike thing my @array = (); push @array, substr( $line, 0, $_, '' ) for @lengths; print join "\t", @array; }
Hope this helps,

Jeroen
"We are not alone"(FZ)
Update: Just stick to unpack as Hofmator says. It gives you all in one line:

my @array= unpack 'a1a20a20a5', $line;
I couldn't get it to strip trailing spaces/nulls with A or Z or @, though.


Comment on Re: Regex Matching
Select or Download Code
Re: Re: Regex Matching
by kbradford (Novice) on Jul 05, 2001 at 20:54 UTC
    Using substr seemed to work. Didn't use it in an array though, just set each one to a scalar and stuck it in a while loop. Works great. Thanks guys!

    Kevin

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-07-12 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls