Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > been using Java too long: please help with dynamic "our" declaration

Reply
Thread Tools

been using Java too long: please help with dynamic "our" declaration

 
 
Robert Watkins
Guest
Posts: n/a
 
      01-25-2006
I've been away from Perl too long, folks, and I'm rusty.

Can't figure out how to declare a few dynamically generated names (i.e.
they could change with each run of the script) as "our" vars.

The idea is to use the names as filehandles, and to write to different
files based on what's found:

--------------------------------------------------------
our $name;
*name = *File::Find::name;

// this is the equivalent of what the script might see
// from the dynamic input:
my @statuses = ("New", "Updated", "Commented and Updated");

my $statuses = '(' . join("|", @statuses) . ')';
my $data;
my ($fh, $filename);

foreach $fh (@statuses) {
$us = $fh;
$us =~ s/\s+//g;
$filename = "blah.$us.list";
open($fh, ">$filename") or die "Could not create $filename: $!\n";
}

File::Find::find( {wanted => \&wanted, follow => 1}, CONTENT_DIR);

foreach $fh (@statuses) {
close($fh);
}

sub wanted
{
local $/;
my $data;
if (/^(sect0|withdrawal)-meta\.html\z/s) {
open(FH, "<$name") or warn "Can't open $name: $!\n";
$data = <FH>;
close(FH);
if ($data =~ /<meta name="unitStatus" content="($statuses)">/) {
$fh = $1;
print $fh "$name\n";
}
}
}
--------------------------------------------------------

Any suggestions?

Thanks,
-- Robert
 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      01-25-2006
Robert Watkins wrote:
> if (/^(sect0|withdrawal)-meta\.html\z/s) {


Did you mean to say something like:
if (my ($name) = (/^(sect0|withdrawal)-meta\.html\z/s)) {

Because I can't see where you're getting a value for $name in the code
you posted.

BTW, are you on UNIX or Windows?

--
http://DavidFilmer.com

 
Reply With Quote
 
 
 
 
Robert Watkins
Guest
Posts: n/a
 
      01-25-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1138220443.432428.58930
@g49g2000cwa.googlegroups.com:

> Because I can't see where you're getting a value for $name in the code
> you posted.
>

our $name;
*name = *File::Find::name;

> BTW, are you on UNIX or Windows?
>

UNIX

But what about getting the right values into $fh and using them as
filehandles?

-- RW
 
Reply With Quote
 
Robert Watkins
Guest
Posts: n/a
 
      01-25-2006
Jim Gibson <(E-Mail Removed)> wrote in news:250120061244141829%
(E-Mail Removed):

> Yes. Don't use dynamically generated variables. Use a hash of
> filehandles instead:
>

Brilliant. Thank you. Obviously this is one to remember.
-- RW

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      01-26-2006
Robert Watkins <(E-Mail Removed)> wrote:
> Jim Gibson <(E-Mail Removed)> wrote in news:250120061244141829%
> (E-Mail Removed):
>
>> Yes. Don't use dynamically generated variables. Use a hash of
>> filehandles instead:
>>

> Obviously this is one to remember.



That's how it is with most Frequently Asked Questions.

perldoc -q filehandle

How can I make a filehandle local to a subroutine? How do I pass file-
handles between subroutines? How do I make an array of filehandles?


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with hash - been too long working in Perl JerryP Perl Misc 2 10-28-2007 02:47 AM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 02:34 PM
I need help I has been over 6 months since I've been able to do the system check for updates Marc Computer Support 8 07-25-2005 07:04 PM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM
Intel C++ 8.0 : declaration hides declaration Alex Vinokur C++ 4 04-05-2004 09:49 PM



Advertisments