LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-20-2007, 06:55 AM   #1
disruptive
Member
 
Registered: Dec 2005
Posts: 76

Rep: Reputation: 15
perl script, paired data


Hi

I am having trouble trying to read in name, value pair data from a text file. I want each name and value on each line and be able to check the value of each name or value indepently (stored in sep varables). I seem to have tied myself in knots trying to get this working.

#!/usr/bin/perl

$LOGFILE = "myfile.txt";
open(LOGFILE) or die("Could not open log file.");
foreach $line (<LOGFILE>) {
chomp($line); # remove the newline from $line.
# do line-by-line processing.
# print $line;
($name, $value) = split(' ', $line);
print $name $value;

}

Thanks
 
Old 02-20-2007, 07:50 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Please use [CODE] tags in your post to improve readability.

I'm having difficult understanding what you want. Can you provide example input and the output you would expect for that input?
 
Old 02-20-2007, 07:51 AM   #3
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
And what is the contents of the myfile.txt? Its very likely that they are not separated by a single space, and so the splits fails.

Cheers!
 
  


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
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 03:23 AM
Perl: $data[$i]->[$j] problem PB0711 Programming 3 05-09-2006 12:11 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

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

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