Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
more useful options
 
PerlMonks  

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

/sunstorage_kvm_images/kvm_images/images/

junkvm

-vda.img

/sunstorage_kvm_images/kvm_images/images/junkvm-vda.img

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

/sunstorage_kvm_images/kvm_images/images/Debian

-vda.img

/sunstorage_kvm_images/kvm_images/images/RHEL

-vda.img

/sunstorage_kvm_images/kvm_images/images/RHEL1

-vda.img

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 (Prior) on Dec 12, 2012 at 18:05 UTC

    chomp @VMSHUT;
    perhaps?


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (21)
As of 2014-04-17 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (453 votes), past polls