Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: appending a variable

by Fletch (Bishop)
on Apr 28, 2022 at 20:24 UTC ( [id://11143401]=note: print w/replies, xml ) Need Help??


in reply to Re^2: appending a variable
in thread appending a variable

Aktchually they compile down to the same thing under the hood (because the former is just syntactic sugar for the latter more or less):

$ perl -MO=Deparse,-p,-q -E 'my $foo = qq{a_${blah}_b}; my $bar = q{a_ +} . $blah . q{_b};' use feature 'current_sub', 'bitwise', 'evalbytes', 'fc', 'postderef_qq +', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval'; (my $foo = 'a_' . $blah . '_b'); (my $bar = 'a_' . $blah . '_b'); -e syntax OK

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^4: appending a variable
by pragovnj (Acolyte) on Apr 28, 2022 at 21:13 UTC
    Hi,

    I got an error "Can't call method "YYYYmmddHHMMSS" on an undefined value" at $FN_OUTPUT This is my code

    my $vmstr = "zldcdyh1bdce2d14-xxx-vccpohr-correlator-0"; my ($opstr) = $vmstr =~ /-(\d\d)$/; #using the value of $vmstr + of the VM but with an added 0 my $OPinst = "/PMOSS_SIPNBVQM_5MIN_OHDR_${YYYYmmddHHMMSS$opstr}"; my $P3inst = "/PMOSS_P3_SIPNBVQM_5MIN_OHDR_${YYYYmmddHHMMSS$opstr +}"; $FN_OUTPUT = "$DST_DIR${OPinst}_${INSTANCE}_$$"; # Suff +ixes added later: .processing .completed $FN_P3_OUTPUT ="$DST_DIR${P3inst}_${INSTANCE}_$$"; # Suf +fixes added later: .processing .completed

    Is this incorrect

      Yes, it is incorrect. You now have a $ inside braces - why have you done that?

      Fixing these 8 lines in isolation gives:

      my $vmstr = "zldcdyh1bdce2d14-xxx-vccpohr-correlator-0"; my ($opstr) = $vmstr =~ /-(\d\d)$/; #using the value of $vmstr + of the VM but with an added 0 my $OPinst = "/PMOSS_SIPNBVQM_5MIN_OHDR_$YYYYmmddHHMMSS$opstr"; my $P3inst = "/PMOSS_P3_SIPNBVQM_5MIN_OHDR_$YYYYmmddHHMMSS$opstr" +; $FN_OUTPUT = "$DST_DIR${OPinst}_${INSTANCE}_$$"; # Suff +ixes added later: .processing .completed $FN_P3_OUTPUT ="$DST_DIR${P3inst}_${INSTANCE}_$$"; # Suf +fixes added later: .processing .completed

      Note however that $INSTANCE is undefined. It is always best to provide an SSCCE.


      🦛

        Hi,

        After removing the inside braces, there is no error. However, I am not seeing the value of $opstr added to YYYmmddHHMMSS. It should be YYYmmddHHMMSS00 in this case. PMOSS_P3_SIPNBVQM_5MIN_OHDR_20220428221115__31571.processing should be PMOSS_P3_SIPNBVQM_5MIN_OHDR_2022042822111500__31571.processing $INSTANCE is something which the server adds and in this case it is 31571.

        my ($opstr) = $vmstr =~ /-(\d\d)$/; #using the value of $vmstr of +the VM but with an added 0 my $OPinst = "/PMOSS_SIPNBVQM_5MIN_OHDR_$YYYYmmddHHMMSS$opstr"; my $P3inst = "/PMOSS_P3_SIPNBVQM_5MIN_OHDR_$YYYYmmddHHMMSS$opstr" +; $FN_OUTPUT = "$DST_DIR${OPinst}_${INSTANCE}_$$"; # Suff +ixes added later: .processing .completed $FN_P3_OUTPUT ="$DST_DIR${P3inst}_${INSTANCE}_$$"; # Suf +fixes added later: .processing .completed

Log In?
Username:
Password:

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

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

    No recent polls found