Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: how to check whether a particular word exists in filename

by Preceptor (Deacon)
on Jul 03, 2013 at 19:24 UTC ( [id://1042260]=note: print w/replies, xml ) Need Help??


in reply to how to check whether a particular word exists in filename

Edited, because it's wrong.

  • Comment on Re: how to check whether a particular word exists in filename

Replies are listed 'Best First'.
Re^2: how to check whether a particular word exists in filename
by ww (Archbishop) on Jul 03, 2013 at 22:55 UTC
    "...but not 'CHECK_ABC123_A1.txt' "

    Nope! Not true.

    C:\>perl -E "my $s='CHECK_ABC123_A1.txt';say $s if ($s =~ m/^CHECK_(\w ++)\.txt/ );" CHECK_ABC123_A1.txt

    or, alternately,

    #!/usr/bin/perl use 5.016; use strict; use warnings; # 1042260 my $s='CHECK_ABC123_A1.txt'; if ( $s =~ m/^CHECK_(\w+)\.txt/ ) { say "\t \$1 is: $1\n\t and the regex matched the source string."; } else { say "\t Nope. Regex didn't match \$s."; } =head OUTPUT: $1 is: ABC123_A1 and the regex matched the source string. =cut

    Pls test your advice... (unless you were trying to get a clueless OP to turn in homework with an error).


    If you didn't program your executable by toggling in binary, it wasn't really programming!

      Nope! Not true.

      That is because in the character class [A-Za-z0-9] there is no underscore, and Preceptor assumed that would be equivalent to \w .
      \w , however, is [A-Za-z0-9_] and thus includes the underscore.

      Cheers, Sören

      (hooked on the Perl Programming language)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found