开发者_如何转开发I am trying to create a file path out of a predetermined path and a variable which is a folder inside the pre determined path.
The predetermined part of the path is /sys/kernel/scst_tgt/targets/iscsi/
The next folder is an address for an iSCSI target like iqn.2011-08.com.solignis:datastore2
Then the last part is something like /enabled
which is a file that tells the state of the target.
When I try to print the full path with the variable $target_name
being replaced with the name of the iSCSI target. The resulting output looks like this
/sys/kernel/scst_tgt/targets/iscsi/iqn.2011-08.com.solignis:datastore2
/enabled
It puts the enabled part on a new line. I can't figure out what is going on
Here is the code for the sub routine I was working on:
sub target_enabled {
my $target_name = shift;
my $target_state_file = "/sys/kernel/scst_tgt/targets/iscsi/$target_name/enabled";
print "$target_state_file\n";
}
Looks like you have a newline at the end of $target_name
. So:
chomp $target_name;
And if that doesn't work (because you may have for example \r\n
from a windows file):
$target_name =~ s/\s+\z//;
It looks like $target_name has a line feed at the end. Check subroutine caller's argument.
(EDIT:) You can use chop
to remove the line feed if it is always there.
chop $target_name;
精彩评论