Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Check last character of a string

by Perlbotics (Bishop)
on Aug 06, 2008 at 09:23 UTC ( #702573=note: print w/replies, xml ) Need Help??


in reply to Check last character of a string

Do you mean  $location .= '\\' unless $location =~ m(\\$); ? (Variations: chomp and m(\\\Z) )

Replies are listed 'Best First'.
Re^2: Check last character of a string
by theroninwins (Friar) on Aug 06, 2008 at 09:28 UTC
    Well it fails as in I need the string to end with \ because I use it as a folder name adding filenames to it. So when the ARGV does not end with \ the adding goes wrong.

      Have you thought about using File::Spec->catfile instead?

      Hi, for me this works:
      #!/usr/bin/perl use strict; my @tests = qw( path1 paht2\ ); for my $location (@tests) { print "before: '$location'\n"; $location .= '\\' unless $location =~ m(\\$); print "after: '$location'\n"; } __END__ before: 'path1' after: 'path1\' before: 'paht2\' after: 'paht2\'
Re^2: Check last character of a string
by theroninwins (Friar) on Aug 06, 2008 at 09:43 UTC
    yes but now i add it if it is there or not. I only need to add it when it is not there.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://702573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2022-05-22 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?