Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Regex condition

by Win (Novice)
on Oct 23, 2007 at 13:54 UTC ( [id://646686]=perlquestion: print w/replies, xml ) Need Help??

Win has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Regex condition
by gamache (Friar) on Oct 23, 2007 at 14:00 UTC
    It looks like you want to be using split, maybe like:
    my @fields = split /\t/, $_;

      You forgot to remove the trailing newline. (Note the \n in the OP's regex.)

      chomp; my @fields = split /\t/, $_;

      And if you want to keep empty trailing fields, you'll need to specify the third parameter.

      chomp; my @fields = split /\t/, $_, -1;
Re: Regex condition
by ikegami (Patriarch) on Oct 23, 2007 at 14:24 UTC
    Hi Win. Line 20 of your input is malformed. You can tell from the second error message.
Re: Regex condition
by johngg (Canon) on Oct 23, 2007 at 15:10 UTC
    I don't know what the problem is since you don't give us enough information to go on, such as, what are "the lines" you are matching against? However, two things about your code occur to me.

    When you are matching against something in $_, you don't have to say $_ =~ /.../ but can just use /.../ as the match will be against $_ by default.

    You don't have to put square brackets around the \d as it is already a character class denoting digits.

    Cheers,

    JohnGG

Re: Regex condition
by mwah (Hermit) on Oct 23, 2007 at 15:20 UTC
    I've written this but it is not processing the lines correctly.

    win, there has been a reply to your post: how to split this on tabs, but if its required to do with regexes, your project condenses to sth. like this:

    ... open my $filehandle, '<', 'win.ini' or die "with style $!"; while( <$filehandle> ) { if( (my @fields = /^\d+ | [^\t]+/xg) == 8 ) { print "all 8 elements found: @fields\n" } } ...

    Regards

    mwa

    correction: [^\t] replaced [^\s], this is what I used in a small test run (and forgot to modify after this.)

Re: Regex condition
by roboticus (Chancellor) on Oct 24, 2007 at 00:43 UTC
    Win:

    You might wanna change the '\t's in your parenthesis to '\d's instead. Right now your regex is looking for a number followed by a mess of tabs....followed by newline.

    ...roboticus

    Update: Need new glasses...

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Regex condition
by GrandFather (Saint) on Oct 24, 2007 at 01:29 UTC

    Do you really want to be using Text::CSV or Text::xSV?


    Perl is environmentally friendly - it saves trees

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found