in reply to Search for abcNUMBERdef, make it a variable, then do math?

make it a variable, for example $12345

Not sure why you would want to, but you cannot create a variable starting with a numeric explicitly, you would have to have 12,345 capturing parentheses groups.

I'm not certain what it is you want, but would this do?
#!/usr/bin/perl use warnings; use strict; my %nums; @nums{qw(today yesterday this last)} = undef; my $alts = join('|',keys %nums); while (<DATA>) { /($alts)(\d+)\1/; $nums{$1} = $2; } for my $key (keys %nums) { my $ans = ($nums{$key} * 0.4)/100; print "$key: $ans (from $nums{$key})\n" } __DATA__ Today: today408today Clicks: 34 Yesterday: yesterday555yesterday Clicks: 61 This Month: this11360this Clicks: 812 Last Month: last5350last Clicks: 454

Replies are listed 'Best First'.
Re^2: Search for abcNUMBERdef, make it a variable, then do math?
by Jesse Smith (Acolyte) on Jan 22, 2011 at 09:10 UTC
    I'll try that out and post back. I'm just trying to change Today: today408today Yesterday: yesterday555yesterday This Month: this11360this Last Month: last5350last in to Today: 1.63 Yesterday: 22.22 This Month: 45.44 Last Month: 21.40 40% of what the number is, with the period added. By doing this math for each of them. For example... Today: today408today would do 408*.4/100=1.63200 with the '200' part taken off.
      SSH spits out
      root@wor [/home/site82/public_html/cgi-bin]# perl stats.cgi Prototype mismatch: sub main::head: none vs ($) at stats.cgi line 19 today: 0 (from ) last: 0 (from ) this: 0 (from ) yesterday: 0 (from )
      The first part of the script is
      if (length ($ENV{'QUERY_STRING'}) > 0){ $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $buffer); foreach $pair (@pairs){ ($name, $value) = split(/=/, $pair); $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg +; $in{$name} = $value; } } my $id = param('id'); use LWP::Simple; $id2 = get ("http://www.domain.com/stats.php?id=$id");
      and Line 19 is use LWP::Simple;
        Prototype mismatch: sub main::head: none vs ($) at stats.cgi line 19

        See CAVEAT in the LWP::Simple docs:

        Note that if you are using both LWP::Simple and the very popular CGI.pm module, you may be importing a head function from each module, producing a warning like "Prototype mismatch: sub main::head ($) vs none". Get around this problem by just not importing LWP::Simple's head function, like so:

        use LWP::Simple qw(!head); use CGI qw(:standard); # then only CGI.pm defines a head()

        As for "The first part of the script is" part:  why are you parsing the QUERY_STRING yourself, when you're using CGI.pm anyway — as the warning and your line my $id = param('id') indicates?  CGI.pm does the parsing already, so you can just drop that code...