in reply to Re: HTML::Parser / Regex
in thread HTML::Parser / Regex

Hi eyepopslikeamosquito,

Thanks for your sample code!

However I come across with the error "Can't use global $1 in "my"" This isn't the first time I see them, I tried googled and get around with it, but unfortunately nothing worked.

As I am still reading the beginners' material, for my knowledge, I would think that I need $_ or $1, to scan for current lines?

And I figured you are the best person I could ask for advice?!

Replies are listed 'Best First'.
Re^3: HTML::Parser / Regex
by kcott (Archbishop) on May 29, 2017 at 03:34 UTC
    "... the error "Can't use global $1 in "my"" ..."

    Somewhere in your code, you have "... my $1 ...". Here's a couple of examples:

    $ perl -e 'my $1;' Can't use global $1 in "my" at -e line 1, near "my $1" Execution of -e aborted due to compilation errors. $ perl -e 'my $1 = 42;' Can't use global $1 in "my" at -e line 1, near "my $1 " Execution of -e aborted due to compilation errors.

    You can find the full description of the problem from "perldiag - Perl diagnostic messages". Until you're familiar with that document, it can be a bit difficult finding the information. In this instance, you'd need to search for "Can't use global" (not "Can't use global $1"). Doing so, locates this:

    Can't use global %s in "%s"
    (F) You tried to declare a magical variable as a lexical variable. This is not allowed, because the magic can be tied to only one location (namely the global variable) and it would be incredibly confusing to have variables in your program that looked like magical variables but weren't.

    While you're learning, you may find it useful to use the diagnostics pragma. Put this line near the start of your code:

    use diagnostics;

    That will give you a full description, rather than the somewhat terse shortened form.

    Important: That pragma is intended as a developer tool. Do not leave it production code.

    — Ken

Re^3: HTML::Parser / Regex
by AnomalousMonk (Archbishop) on May 29, 2017 at 02:59 UTC
    ... the error "Can't use global $1 in "my""

    What is the specific code that produces this error? If you don't show us the code, we can only make more or less wild quesses. This just wastes our time and yours. Please see How do I post a question effectively? and How (Not) To Ask A Question.

    Update: BTW: I ran the code eyepopslikeamosquito posted here under Perl 5.8.9 and I get the advertised output with no errors or warnings.


    Give a man a fish:  <%-{-{-{-<