Professional Web Applications Themes

"Simple" regex advice (possibly '/' causing an issue?) - Perl / CGI

Ian.H wrote: (snipped) > my $scan_results = `$scan_command $scan_path`; > $scan_results =~ s#.*Switches: -ARCHIVE -PACKED > -COLLECT\n\n(.*)\n\nResults of virus scanning:.*#$1#s; > if (m#^$scan_path(.*?)->(.*)\s+Infection:\s+(.*)$#) { > ($user,$attachment, $infection) = ($1, $2, $3); > Use of uninitialized value in pattern match (m//) at ./mail_scan.pl line 13 You are trying to use Perl's $_ but it does not exist, for your context. if (m#^$scan_path .... if ($scan_results =~ m#^$scan_path .... It is a good practice to always use explicit variable names even when $_ is used invisibly. You have fallen into this pitfall of thinking $_ is there, is defined. It is not. ...

  1. #1

    Default Re: "Simple" regex advice (possibly '/' causing an issue?)

    Ian.H wrote:

    (snipped)
    > my $scan_results = `$scan_command $scan_path`;
    > $scan_results =~ s#.*Switches: -ARCHIVE -PACKED
    > -COLLECT\n\n(.*)\n\nResults of virus scanning:.*#$1#s;
    > if (m#^$scan_path(.*?)->(.*)\s+Infection:\s+(.*)$#) {
    > ($user,$attachment, $infection) = ($1, $2, $3);
    > Use of uninitialized value in pattern match (m//) at ./mail_scan.pl line 13

    You are trying to use Perl's $_ but it does not exist, for your context.

    if (m#^$scan_path ....

    if ($scan_results =~ m#^$scan_path ....


    It is a good practice to always use explicit variable names
    even when $_ is used invisibly. You have fallen into this
    pitfall of thinking $_ is there, is defined. It is not.

    Use explicit variable names always and you won't encounter
    this problem of "shortcut pitfalls."


    Purl Gurl
    Purl Gurl Guest

  2. #2

    Default Re: "Simple" regex advice (possibly '/' causing an issue?)

    Purl Gurl wrote:
    > Ian.H wrote:
    (snipped)
    > > Use of uninitialized value in pattern match (m//) at ./mail_scan.pl line 13
    > You are trying to use Perl's $_ but it does not exist, for your context.
    > if (m#^$scan_path ....
    > if ($scan_results =~ m#^$scan_path ....
    > It is a good practice to always use explicit variable names
    > even when $_ is used invisibly. You have fallen into this
    > pitfall of thinking $_ is there, is defined. It is not.

    Below is an example of what you are experiencing.

    Should you try to print regex numerical variables
    immediately after line 8 matching, warnings will
    generate three "uninitialized value" messages.
    Other subsequent code which relies on your malformed
    match operator, will also generate the same message,
    leading you to believe an error exists elsewhere.

    Use explicit variable names to avoid this pitfall.


    Purl Gurl
    --

    #!perl -w

    our ($variable, $user, $attachment, $infection);

    $variable = "Test One Here";

    ## LINE 8 NEXT:
    if (m#^(T\w+) (\w*) (\w*)#)
    { ($user,$attachment, $infection) = ($1, $2, $3); }

    if ($variable =~ m#^(T\w+) (\w*) (\w*)#)
    { ($user,$attachment, $infection) = ($1, $2, $3); }

    print "Match Out: $1 $2 $3";


    PRINTED RESULTS:
    ________________

    Use of uninitialized value in pattern match (m//) at test.pl line 8.
    Match Out: Test One Here
    Purl Gurl Guest

  3. #3

    Default Re: "Simple" regex advice (possibly '/' causing an issue?)

    "Ian.H [dS]" <ianWINDOZEdigiserv.net> writes:
    > Evening all =)
    Due to the propagation delays of Usenet, the timezone differences in
    an international forum and the fact that most people only read
    newsgroups a couple of times a day it is totally unsafe to assume that
    it is evening to all. :-)

    > #!/usr/bin/perl
    [ snip 11 lines of code that doesn't do anything that would set $_ ]
    > if (m#^$scan_path(.*?)->(.*)\s+Infection:\s+(.*)$#) {
    > Use of uninitialized value in pattern match (m//) at ./mail_scan.pl line
    > 13
    Well, you've done nothing to set $_ (so it'll be undef) then you do a
    m// with no =~ (so it'll act on $_, which, as I said, is undef).

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley Guest

Similar Threads

  1. FileReference upload -> "script is causing Flash to runslowly"?
    By timothee_groleau in forum Macromedia Flash Player
    Replies: 1
    Last Post: October 10th, 03:43 AM
  2. Replies: 1
    Last Post: August 13th, 01:55 AM
  3. "replace pages" / "rotate pages" orientation issue
    By mr_feroz@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 0
    Last Post: April 23rd, 04:38 PM
  4. Replies: 0
    Last Post: August 25th, 03:50 PM
  5. "regex literal in condition"
    By Daniel Carrera in forum Ruby
    Replies: 3
    Last Post: July 23rd, 11:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139