Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi Erez,

In scalar context:

my $build = ($vdata=~/=(\d+)$/);
you're correct; you will get 0 or 1.  But in list context:
(my $build) = ($vdata=~/=(\d+)$/);
you will get the captured values.  For example:
use strict; use warnings; my $text = "The quick brown fox jumps over the lazy dog"; my ($h, $i, $j) = $text =~ /(\S*h\S*).*?(\S*i\S*).*?(\S*j\S*)/; print "$h, $i, $j\n"; __END__ Output: The, quick, jumps

Hi roboticus,

I, too, thought this a simple case of not matching the newline.  However, I can't explain why I'm getting the following:

use strict; use warnings; # my $dir1 = 'Z:\My Documents\Workspace'; # my $versionFile = "$dir1\\version.txt"; # open (VFILE, $versionFile)|| die $!; # my $vdata= <VFILE>; # close (VFILE); try_this("Version=2010-09-01_17-29-04 Build=26"); try_this("Version=2010-09-01_17-29-04 Build=26\n"); try_this("Version=2010-09-01_17-29-04 Build=26\n\n"); sub try_this { my ($vdata) = @_; print "=" x 69, "\n"; print "Str: [$vdata]\n"; printf "Asc: %s\n\n", join ' ', map { ord $_ } split //, $vdata; (my $build) = ($vdata=~/=(\d+)$/); print "Build = [$build]\n\n";#this is the problem line } __END__ Output: ===================================================================== Str: [Version=2010-09-01_17-29-04 Build=26] Asc: 86 101 114 115 105 111 110 61 50 48 49 48 45 48 57 45 48 49 95 49 55 45 50 57 45 48 52 32 66 117 105 108 100 61 50 54 Build = [26] ===================================================================== Str: [Version=2010-09-01_17-29-04 Build=26 ] Asc: 86 101 114 115 105 111 110 61 50 48 49 48 45 48 57 45 48 49 95 49 55 45 50 57 45 48 52 32 66 117 105 108 100 61 50 54 10 Build = [26] ===================================================================== Str: [Version=2010-09-01_17-29-04 Build=26 ] Asc: 86 101 114 115 105 111 110 61 50 48 49 48 45 48 57 45 48 49 95 49 55 45 50 57 45 48 52 32 66 117 105 108 100 61 50 54 10 10 Use of uninitialized value $build in concatenation (.) or string at D:\Documents and Settings\jonorton\a.pl line 25. Build = []

The first string (no newlines) matches as expected, and the third (2 newlines) fails, also as expected.  But the second (1 newline) matches, despite the newline at the end.  I'm not sure what to make of that.

This is on perl v5.10.0 for MSWin32-x86-multi-thread (Windows xp), binary build 1004 from ActiveState.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re^3: Use of uninitialized value when using regex by liverpole
in thread Use of uninitialized value when using regex by PerlScholar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-23 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found