Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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
Replies are listed 'Best First'.
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
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.

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 musing on the Monastery: (6)
As of 2015-11-29 02:40 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls