in reply to how to chop last character from a string

Why does $ARGV[0] contains a newline? chop will remove the last character, no matter what it is. The following should be more reliable than chop:

my $arg = $ARGV[0]; $arg =~ s/\*$//; # Remove trailing '*', if any.

If there really is a newline, add chomp($arg) between those two lines.

Of course, you probably you could forget about removing the '*' and use File::Glob or File::DosGlob to interpret the argument (if you're trying to list the files matching the spec).

Replies are listed 'Best First'.
Re^2: how to chop last character from a string
by suaveant (Parson) on Jan 03, 2006 at 21:31 UTC
    Why add a chomp, if you are already regexping just give it a
    $arg =~ s/\*\n?$//;
    if you actually want to get rid of trailing newlines.... maybe add a \r? for completeness' sake

                    - Ant
                    - Some of my best work - (1 2 3)