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-02-2010, 06:40 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
perl help


Guys,
please look at the following code:
Code:
#!usr/bin/perl -w
use strict;
open RMLOOK, "ip_names.lookup.removed";
open LOOK, "ip_names.lookup";
#open OUT, ">out.txt";
#open RMOUT, ">myout.txt";
my (@r,@l,@a,@b);
while(defined(my $bar=<LOOK>))
{
	@a=split("\t",$bar);
	while(defined(my $inf=<RMLOOK>))
	{
#		print $a[5];
		@b=split("\t",$inf);
		#print $b[0],"=>",$a[0],"\n";
		if( $a[0] eq $b[0] )
		{
#			print "$bar$inf";
		}	
	}
	print $a[5];
}
this is printing different values. Where as:
Code:
#!usr/bin/perl -w
use strict;
open RMLOOK, "ip_names.lookup.removed";
open LOOK, "ip_names.lookup";
#open OUT, ">out.txt";
#open RMOUT, ">myout.txt";
my (@r,@l,@a,@b);
while(defined(my $bar=<LOOK>))
{
	@a=split("\t",$bar);
	while(defined(my $inf=<RMLOOK>))
	{
		print $a[5];
		@b=split("\t",$inf);
		#print $b[0],"=>",$a[0],"\n";
		if( $a[0] eq $b[0] )
		{
#			print "$bar$inf";
		}	
	}
#	print $a[5];
}
The input files being:
cat ip_names.lookup
Code:
IPAddress	Hostname	Owner	CustomerUsing	NetworkType	Location	EmailAddress	AssetType	Service
.................
192.168.0.9	aaaa	bbb world mant	aaa world mant	industry	nY	a@gmail.com	DEsk	N/A
192.168.0.9	aaaa	bbb world mant	aaa world mant	industry	nY	a@gmail.com	DEsk	N/A
.................
cat ip_names.lookup.removed
Code:
IPAddress	Hostname	Owner	CustomerUsing	NetworkType	Location	EmailAddress	AssetType	Service	Type	no#	Date
.................
192.168.0.9	aaaa	bbb world mant	aaa world mant	industry	nY	a@gmail.com	DEsk	N/A	Removed	345	06132007
192.168.0.9	aaaa	bbb world mant	aaa world mant	industry	nY	a@gmail.com	DEsk	N/A	Removed	345	06132007
.................
this printing the same value throughout the loop.
why???

Last edited by ashok.g; 02-02-2010 at 11:34 PM.
 
Old 02-02-2010, 08:07 AM   #2
eyemole80
Member
 
Registered: Jun 2004
Distribution: Fedora Core 1
Posts: 47
Blog Entries: 1

Rep: Reputation: 16
Be more elaborative please. What were the input files and what type of output your are expecting. Really could not get that what you want to achieve?
 
Old 02-02-2010, 06:56 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. you should definitely chomp($bar) and chomp($inf) after reading, otherwise the last element in each instantiation of @a and @b will contain an newline char
http://perldoc.perl.org/functions/chomp.html
2. The first version prints $a[5] for each rec in LOOK (outer loop), the 2nd prints $a[5] for every rec in RMLOOK (inner loop)
 
Old 02-02-2010, 11:35 PM   #4
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Please find the edited thread above....
 
  


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
Trying to find libmail-mbox-messageparser-perl and libmailtools-perl for Fedora 11 almac58 Linux - Software 4 11-18-2009 03:17 AM
LXer: Installing Eclipse, the Epic Perl plugin and my first Perl GUI program LXer Syndicated Linux News 0 05-08-2009 06:41 PM
RHEL4u2 perl localtime() call issues (perl & glibc) Brad.Scalio@noaa.gov Linux - Enterprise 3 01-23-2007 09:27 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM

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

All times are GMT -5. The time now is 09:25 PM.

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