LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
LinkBack Search this Thread
Old 10-20-2004, 11:38 AM   #1
amytys
LQ Newbie
 
Registered: Sep 2004
Posts: 11

Rep: Reputation: 0
Issues calling sort from perl using pipe as delimiter


I'm trying sort a file by calling the sort program from w/in Perl.

The issue is that I want to sort on given columns, and my delimiter is the pipe. I can't get the pipe to take.

I've tried:

system("sort -t\| -2 +3 $OUTPUT_DIR/file.txt > OUTPUT_DIR/file.srt");

and

system('sort -t\| -2 +3 $OUTPUT_DIR/file.txt > OUTPUT_DIR/file.srt');

Neither seems to work. I've done this in the past with underscores as delimiters, but not w/pipe... worked fine! I really want to avoid doing a hack, changing the given pipe to a more suitable character before I call the sort. I know this can be done, I'm just lost in the syntax. Perhaps something from the perlop would help?
 
Old 10-20-2004, 09:35 PM   #2
Chrax
Member
 
Registered: Apr 2004
Distribution: Dapper
Posts: 167

Rep: Reputation: 31
Quote:
system("sort -t\| -2 +3 $OUTPUT_DIR/file.txt > OUTPUT_DIR/file.srt");
Shouldn't this be
Code:
system("sort -t\| -2 +3 $OUTPUT_DIR/file.txt > $OUTPUT_DIR/file.srt");
Other than that, I don't see any reason it shouldn't work, unless it's trying to extend your variables beyond their bounds. For example, one time I needed to use ...$var_300... and it assumed my variable wasn't $var but $var_300.

If this happens, this is sort of a hack to get around that.
Code:
$tosystem = "sort -t\| -2 +3 " + $OUTPUT_DIR + "/file.txt > " + $OUTPUT_DIR + "/file.srt";
system("$tosystem");
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling KDE/C++ functions from python/perl and vice versa yogeshm02 Programming 1 04-30-2005 11:54 AM
calling a c++ binary inside a perl script Blue_muppet Programming 3 08-28-2004 11:31 PM
Hash-sort like in PERL in C++ nyk Programming 4 06-11-2004 08:40 AM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 08:24 PM
calling subs from within Perl bickford Programming 8 08-13-2000 07:10 PM


All times are GMT -5. The time now is 08:16 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration