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

Hello All, I am trying to run a mysql command in a perl script via the system command, it works at the command line but not in the script I get the error:
Unrecognized escape \w passed through at rdscopy.pl line 22. Unrecognized escape \d passed through at rdscopy.pl line 22.
Can you help please, the command is below: system qq{mysql -hhostname -uproot -password -e 'SELECT feed_table FROM database.stream_table where id = 447' | perl -ne 'print if /\w+\d+/' };

Replies are listed 'Best First'.
Re: perl system command
by choroba (Cardinal) on Nov 09, 2016 at 22:36 UTC
    That's what you get from passing a backslashed w od d to qq :
    print qq{\d\w};

    Double the backslashes, or use q instead, as you don't seem to need interpolation.

    Moreover, calling perl from perl is usually not needed. Read the output of the command and process it in the script itself. What about using DBI instead of shelling out to mysql ?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thank you double back-slashes worked. I am also using DBI module, but my issue is that I wanted to to split result and perl giving me issues. I have $row = $feed_db->fetchrow_array() ; $row is social_going_home , but I only want home, I tried grepping, but it only returns 1 (which means its found) .I can split it and store values into an array and search the array, but I want a one liner.can you help?
      So far in order to get what I want I have to split it and then search through it variable $row is "We_need_feed"
      my $row = $feed_db->fetchrow_array() ; my @words = split (/_/, $row); foreach(@words) { if(/feed*/) { $test="$_"; } } print("$test\n");

        Might something like this be helpful?

        c:\@Work\Perl\monks>perl -wMstrict -le "my $look_for = qr{ (?<! [[:alpha:]]) home (?! [[:alpha:]]) }xms; ;; my $row = 'social_going_home'; my $match = my ($capture) = $row =~ m{ (?<= _) $look_for \z }xmsg; ;; if ($match) { print qq{match, captured '$capture'}; } " match, captured 'home'

        Update: BTW: The pattern  feed* in the match of  if(/feed*/) { ... } matches any of  fee feed feedd feeddd ... Is that what you wanted?


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

        in order to get what I want

        It isn't overly clear what you want. If you have a string with words separated by underscores and just want to return the last such word then you could do this:

        my $row = 'We_need_feed'; my ($last) = $row =~ /[^_]*$/g; print $last;

        or you could split and then pop but maybe extracting the last isn't what you want at all.

Re: perl system command
by NetWallah (Canon) on Nov 09, 2016 at 22:39 UTC
    Alternatively, you could escape the "\" by doubling them like "\\w" and "\\d".

            ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall

Re: perl system command
by Anonymous Monk on Nov 09, 2016 at 22:32 UTC
    you're using a double quoted perl string, it interpolates, try a single quoted string