LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2009, 03:33 PM   #1
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Python to Perl porting help


Okay, so I'm a primarily Python developer who is trying to pick up a bit of perl. To do this, I'm trying to port old code from python to perl, purely as an exercise. The problem is, I'm guessing, the difference between the typing, or more specifically, trying to do everything to Python way.

I'm currently playing with an old script which removes the slug from blogs downloaded from google cache (Don't ask, it was important at the time ) and renames the file to this. A line in the python:
Code:
self.renamer( file, file.replace("%2F","_").split("+")[0].split(":")[2].rstrip("_") )
is giving me so much trouble in perl. Specifically constructing the second argument. I can get so far, though it looks too bloated, I'm sure there is a better way, but the 'rstrip()' bit is the hardest. I've looked at chop(), God help me I tried to change $/ and use chomp(). I've essentially got as far as
Code:
my $str = $file;
$str =~ s/\%2F/_/g;
@split_string = split(/\+/, $str);
$str = @split_string[0];
@split_string = split(/:/, $str);
$str = @split_string[-1];
renamer( "@_[0]$file", "@_[0]$str" );
Which essentially does the same thing as the single line above without, of course, the 'rstrip()' bit.

Could anybody point me in the right direction? Ideally, without giving me the answer or telling me to read a book or follow a guide. I'm comfortable enough with my basic perl skills, its just stuff like this.

Incidentally, this is the original python script
jamescondron.co.uk/slugger.py
 
Old 07-08-2009, 06:54 PM   #2
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
If I understand Python's documentation correctly, rstrip removes specified trailing characters.

You don't want an explicit answer, so my hint is this: take a look at what $ does in a regular expression.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Simple Arithmetic In Bash, Perl and Awk - More Porting LXer Syndicated Linux News 0 05-28-2008 08:41 AM
Python to C++ converter? Or porting this? hedpe Programming 2 09-15-2007 12:26 PM
My needs: Perl vs. Python dave201 Programming 25 08-11-2007 11:13 PM
Perl or Python JJX Programming 4 04-17-2006 02:42 PM
Python or Perl? Boby Programming 2 06-12-2005 10:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration