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

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

Replies are listed 'Best First'.
Re^5: appending a variable
by hippo (Archbishop) on Apr 28, 2022 at 21:35 UTC

    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

        Try this case:

        use strict; use warnings; my $vmstr = "-1"; my $ymmv = "Mileage "; my ($opstr) = $vmstr =~ /-(\d\d)$/; print "$ymmv'$opstr'\n";

        What do you expect should happen. What actually happens. How does it relate to your issue?

        You might like to try without strictures first (comment out the first two lines).

        Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
        my ($opstr) = $vmstr =~ /-(\d\d)$/; will result in an undefined value for $opstr because there is only one digit after the "-" instead of 2 digits.
        Better: >my ($opstr) = $vmstr =~ /-(\d+)$/;

        Why are you ignoring the warnings and errors that Perl is printing out?

        Always put:

        use strict; use warnings;
        at the top of your script.