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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array behaving badly
by blue_cowdawg (Monsignor) on Dec 12, 2012 at 18:05 UTC | |
|
Re: Array behaving badly
by Anonymous Monk on Dec 12, 2012 at 17:58 UTC |