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

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.







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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2018-01-21 05:59 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.