FAQ
Shawn H Corey writes:
close $h1fh or die "could not close $h1: $!\n";
close $h2fh or die "could not close $h2: $!\n";
close $ckfh or die "could not close $ckarr: $!\n";
Output is buffered. The files have to be closed for the last lines to
be printed to the file.
I was pretty sure it would be some basic tenet, I'd over
looked. That happens a lot for me it seems.

Thanks for you time, that made all the difference. After moving the
closures, line counts started to match up.


I do have another question that was only in the background of my first
post.

Is there a canonical way to read a bunch of -f type files into a hash?

I want the end name `$_' on one side and full name `File::Find::name'
on the other...

what happens is the keys start slaughtering each other if you get it
the wrong way round... and even when it ends up right... I wonder
there may still be some chance of names canceling

Doing it like this:

$h1{$File::Find::name} = $_

So far, has agreed with the count I see from `wc -l'. I'd like to
know for sure though if that is a reliable way to do it?

And is there some kind of handy way to turn a hash into a scalar like
can be done to arrays with File::Slurp

What I'm after is a way to grep the list of full names using the
endnames of a similar but not identical list, in order to discover
which names are in the longer list, but not the shorter list.

Writing it to file is one way. And it seem likely to be the better
way really since the lists can be pretty long.

I wondered if this can all be done in the script with hashes somehow.

Here is roughly what I've tried with already compiled lists in disk
files.

So far, I've used the longer list in a for loop one line at a time to
check for the the endname in the longer list as a slurped file.

just briefly.. (code is just made up to show the goal
something like (this is not working code[yet]):

use strict;
use warnings;
use File::Slurp;
use File::Find;
use Cwd;

my $file = './file';
my $var = 'gnus';

[...]

my @longar = read_file($longarfile);
my $shortlist = read_file($shortfile);

open my $gclfh,'>',$file or die "Can't open <$file>: $!";

for(@longar){
chomp;
## isolate just the endname for our purposes
my ($endname) = $_ =~ m/.*\/([^\/]+)$/;

my $ematch;

## No match even on the end name... then we write to
## file
## use \b instead of $ since its a slurped list
if (($ematch) = $shortlist =~ m/(.*$endname)\b/) {
print "$_ MATCHES $ematch\n";
}else {
##
( my $adjusted_line = $_) =~ s/^\.*\/*$var\///;
print "NO MATCH ON $_, writing to <$file>\n";
print $gclfh "$adjusted_line\n";
}
}

close $gclfh;

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedApr 25, '10 at 7:25p
activeApr 25, '10 at 11:46p
posts4
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase