LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-30-2010, 01:17 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
[Perl] hash and while loop - output not right


I am trying to create a script that will give me the subversion latest revision number for various repositories. But the output I am getting is not coming out in the right format.

Code:
#!/bin/env perl

use strict;
use warnings;
use diagnostics;

my $look = '/usr/bin/svnlook';
my $arg1 = 'youngest';

my %hash = (
lua => '/var/svn/lua',
scheme => '/opt/svn/scheme',
);

while ( my ($key, $value) = each(%hash) ) {
        my $ks = system ("$look $arg1 $value");
        print "$key is in version: $ks\n" ;
    }
Current output:

Code:
# 2590
# lua is in version: 0
# 765
# scheme is in version: 0
Expected output:

Code:
lua is in version: 2590
scheme is in version: 765
Thanks.
 
Old 11-30-2010, 04:44 AM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
you could change the system call to
my $ks = `$look $arg1 $value`;

that would capture the output whereas the system call runs the program but does no capturing of output

another option would be to use open with a | to execute the program, then just read on the filehandle to get the output

something like
open($FH, "$look $arg1 $value |") or { die "couldn't run $look for $key" };
my $ks = <$FH>;
close($FH);
 
  


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
Perl Hash query kdelover Programming 5 11-21-2010 09:14 AM
Using hash value as key for other hash in Perl scuzzman Programming 6 02-14-2006 05:08 PM
Perl and Hash automatic PB0711 Programming 3 09-23-2005 02:14 AM
Generating hash in perl ? MikeFoo1 Programming 3 05-21-2005 06:03 PM
Hash-sort like in PERL in C++ nyk Programming 4 06-11-2004 08:40 AM

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

All times are GMT -5. The time now is 03:43 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