Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Array behaving badly

by johnnywhall (Initiate)
on Dec 12, 2012 at 17:12 UTC ( #1008534=perlquestion: print w/ replies, xml ) Need Help??
johnnywhall has asked for the wisdom of the Perl Monks concerning the following question:

OK, it was a chomp, just needed to get it into the right place

#!/usr/bin/perl $OLDVMDIR = "/sunstorage_kvm_images/kvm_images/images/"; print "$OLDVMDIR \n"; $VMNAME = "junkvm"; print "$VMNAME \n"; $VMSFX = "-vda.img"; print "$VMSFX \n"; $CONCAT = $OLDVMDIR . $VMNAME . $VMSFX; print "$CONCAT \n"; @VMSHUT = `cat /tmp/virshlist_shutdown`; foreach $VMSHUT (@VMSHUT) { chomp $VMSHUT; $VMFILE = $OLDVMDIR . $VMSHUT . $VMSFX; print "$VMFILE \n"; }

Hello All,

I have a simple little script where I'm trying to append some text to a string. It works fine until I introduce an array. Here is the script

#!/usr/bin/perl $OLDVMDIR = "/sunstorage_kvm_images/kvm_images/images/"; print "$OLDVMDIR \n"; $VMNAME = "junkvm"; print "$VMNAME \n"; $VMSFX = "-vda.img"; print "$VMSFX \n"; $CONCAT = $OLDVMDIR . $VMNAME . $VMSFX; print "$CONCAT \n"; @VMSHUT = `cat /tmp/virshlist_shutdown`; foreach $VMSHUT (@VMSHUT) { $VMFILE = $OLDVMDIR . $VMSHUT . $VMSFX; print "$VMFILE \n"; }

The first part behaves as expected, it prints the directory, vm name and the -vda.img and concatenates them when I ask. When I introduce the array it adds a new line before the -vda.img string. See below

This I expect





This I do not expect. I thought it was a missing chomp, but that's not fixing it.







Comment on Array behaving badly
Select or Download Code
Re: Array behaving badly
by Anonymous Monk on Dec 12, 2012 at 17:58 UTC

    Am I mistaken, I didn't see any "array" variable in your code whatsoever.
    Your second script is just the same thing with the first one. Please, the more detailed, if you want people's help.

Re: Array behaving badly
by blue_cowdawg (Monsignor) on Dec 12, 2012 at 18:05 UTC

    chomp @VMSHUT;

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1008534]
Approved by tobyink
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (18)
As of 2015-07-02 17:00 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (44 votes), past polls