Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

newb question

by anesthdr (Initiate)
on Sep 04, 2007 at 04:07 UTC ( [id://636827]=perlquestion: print w/replies, xml ) Need Help??

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

I've recently started programming perl and I'm stuck on a piece of code.
Here's the problem (excuse that fact that I've never had formal coding training/been programming for about 2 mos..):

$row_arr_today = $res_sched&#91$row&#93; ##@res_sched is an array o +f arrays for $person(1..$#{$row_arr_today}) { ##cycle through the array$ro +w_arr_today from element 1 $name = $row_arr_today->&#91$person&#93; ##assign to $name the +$person element in that array foreach $row(0..$#namearray) { ## @namearray is another arr +ay of arrays $testname = $namearray&#91$row&#93[0]; if ($testname =~ /($name)/){} ##this line returns the er +ror: ##Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- H +ERE X*/ at loadsched.pl line 66. What basic piece of info am I mis +sing? Thanks };

Edit:g0n - code tags

Replies are listed 'Best First'.
Re: newb question
by ysth (Canon) on Sep 04, 2007 at 04:27 UTC
    When you say /($name)/, you are using the contents of $name as part of the regex to match. $name has a * in it (and could potentially have other characters that are special in a regex).

    Perhaps you mean if ($testname eq $name)? Or if you really want to see if $testname contains the string in $name, say if ($testname =~ /(\Q$name\E)/), or even just if (index($testname, $name) >= 0).

    By the way, are you intentionally skipping the first element in each @$row_arr_today? If not, use 0.., not 1...

Re: newb question
by f00li5h (Chaplain) on Sep 04, 2007 at 04:27 UTC

    The error message you speak of refers to * or ? appearing following nothing (or something that can't be repeated)...

    m/?/ or m/*/ are the most simple ways to get the message. you want to use m/\Q$string_with_regex_chars_in\E/ or quotemeta to interpolate strings that contain regex meta-characters into a pattern.

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

      Thanks All!
Re: newb question
by GrandFather (Saint) on Sep 04, 2007 at 04:18 UTC

    How about you provide a piece of code that can be run and demonstrates the problem?

    It is good practice to use strictures (use strict; use warnings;). That may not help highlight the problem in this case, but strictures are pretty good at catching typos and "silly" errors early rather than late and will save you bulk time and frustration one day soon. ;)

    Update: for my $person ( 1 .. $#{$row_arr_today} ) does not "##cycle through the array" because Perl arrays start at 0 (generally). But you knew that because later you have foreach my $row ( 0 .. $#namearray ) so either the code of the comment is wrong, or at least is misleading. Generally it is considered bad to comment "obvious stuff". It's especially bad when the comment is wrong or misleading!


    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found