in reply to Why can't I use s///

If your sting is always a file path, you could try File::Basename:
use warnings; use strict; use File::Basename qw(basename); my $text = "../files/jack/2012/derpone.pdf"; $text = basename($text); print "$text\n"; __END__ derpone.pdf

Note that .. in your regex means any character, not just dots.

Replies are listed 'Best First'.
Re^2: Why can't I use s///
by njack (Novice) on May 08, 2013 at 16:54 UTC

    Yeah about file::basename my hands are tied since I can't install libraries on the university server, so I can't use it.

    And about the .. it's fine since all my strings begins witn ".." anyway

      It should be installed already because it is a Core module. Give it a try.

      If it doesn't work, use Tip #3 from the Basic debugging checklist

        omg it works!

        thank you! I'd buy you a digital beer.

        Anyway I think I found out the reason.

        my $text="../files/jack/2012/derpone.pdf"; $text = basename($text); my $cgi = CGI->new; #Instantiate a CGI class print $cgi->header, # First we create a header $cgi->start_html('My first Perl website'), # Begin HTML page $cgi->h1('Success'), # create the Tag <h1>TEXT</h1> $cgi->p($text),

        This code works, the second one doesn't

        my $cgi = CGI->new; #Instantiate a CGI class print $cgi->header, # First we create a header $cgi->start_html('My first Perl website'), # Begin HTML page $cgi->h1('Success'), # create the Tag <h1>TEXT</h1> my $text="../files/jack/2012/derpone.pdf"; $text = basename($text); $cgi->p($text),

        It seems I can't initialize variables while printing HTML