Re: Perl programming related question.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16 August 2012 16:28, Lázaro Morales <lazaro@xxxxxxxxxxxxxxxx> wrote:
> Hello folks,
>
> This question is a bit off-topic but the Fedora Community is awesome. This
> is the question, How can I from this string:
>
>    my $url = "http://somesite.org/somefile.zip";;    # Example URL
>
> obtain only this sub-string:
>
>   my $file = "somefile.zip";

Why bother wrestiling with complex regular expressions when someone
else has already done the work? Perl has a URI module ("yum install
perl-URI") which understands how URIs (and URLs) work. I'd recommend
using that.

  use URI;

  my $url = URI->new('http://somesite.org/somefile.zip');
  say $url->path; # prints "/somefile.zip"

Then there's the File::Basename module (included with the Perl
distribution) for dealing with file paths.

  use File::Basename;

  say basename($url->path); # prints somefile.zip

Perl programming gets a lot easier if you use the tools that are already there.

Cheers.

Dave...

-- 
Dave Cross :: dave@xxxxxxxxxxx
http://dave.org.uk/
@davorg
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux