"Rob Dixon" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> joseph wrote:
> >
> > I need help with my script, this supposedly would check a workstation 
> > listed
> > in one file then see if it's not listed on other file, if it 's the case
> > then append it on an output file.Basically what i got is the same 
> > unmodified
> > list just appended on the output file. Where did i got  wrong? TIA.
> >
> > #!/usr/bin/perl -w
> >
> > use strict;
> > use Data::Dumper;
> >
> > open(FL1,"pclist.txt") or die "can't open pclist.txt $!";
> > open(FL2,"smsclient.txt") or die "can't open smsclient.txt $!";
> > open(OUTPUT,">>unlisted.txt") or die "can't open pclist.txt $!";
> >
> > my @smsclient = <FL1>;
> > my @pclist = <FL2>;
> > my %hash = map { $_ => 1 } @pclist;
> >
> > foreach my $key (@smsclient) {
> >    chomp($key);
> >    unless(exists $hash{$key}){
> >    print OUTPUT $key,"\n";
> >     }
> >   }
> >
> >  close(FL1);
> >  close(FL2);
> >  close(OUTPUT);
>
> Hi Joseph
>
> You've used the raw file records in @pclist as keys for your hash, but 
> then
> 'chomp'ed the data in @smsclient before you look for a match. Nothing will
> compare as equal because one set has trailing "\n" characters while the 
> other
> doesn't.
>
> By the way, you're putting the stuff from pclist.txt into @smsclient and 
> vice
> versa, which could confuse things a little.
>
> You may like my version of this program, which works fine with my data. 
> One
> proviso though: I don't know which of your files is which, so you may need 
> to
> swap the filenames. This prints all names in smsclient.txt that aren't in
> pclist.txt.
>
> HTH,
>
> Rob
>
>   use strict;
>   use warnings;
>
>   my %pclist = do {
>     open my $fh, 'pclist.txt' or die $!;
>     chomp (my @data = <$fh>);
>     map { $_ => 1 } @data;
>   };
>
>   open my $fh, 'smsclient.txt' or die $!;
>   open my $out, '>>', 'unlisted.txt' or die $!;
>
>   while (<$fh>) {
>     chomp;
>     print $out "$_\n" unless $pclist{$_};
>   }
>
>   close $out;
>   close $fh;

Hi Rob et al,

 Thank you for the effort, but still it didn't work, I tried to run the 
script in winXP/fedora linux platform just to make sure, still the problem 
persist.
I really don't have any clue why this didn't work while when a try a simple 
predeclared array it did, could this be because of the format of my text 
file?

For sake of clarity the format of these files are like this;

smsclient.txt

wkspc0001
wkspc0002
wkspc0003
so..on

pclist.txt

wkspc0001
wkspc0002
wkspc0005

the former is an exported list of SMS collection with the latter is produce 
by net view > out.txt.  Hoping for any feedback and suggestion, as alway 
thank you very much.

/joseph 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to