Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2020-02-25 03:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (108 votes). Check out past polls.

      Notices?