[24226] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6418 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 19 14:41:45 2004

Date: Mon, 19 Apr 2004 11:40:58 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 19 Apr 2004     Volume: 10 Number: 6418

Today's topics:
        Jessica Simpson showering on a texas beach 7788 <xft.phsm@vfryngrl.com>
        LWP::Simple and utf8 problem <t.goetz@dkfz.de>
        Need HELP with array and hash table comparison (Saya)
    Re: Need HELP with array and hash table comparison <ittyspam@yahoo.com>
        need Regular Expression to remove all non-numerical  <robert@the.com>
    Re: need Regular Expression to remove all non-numerical <jurgenex@hotmail.com>
    Re: need Regular Expression to remove all non-numerical <raisin@delete-this-trash.mts.net>
    Re: need Regular Expression to remove all non-numerical <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: need Regular Expression to remove all non-numerical <vetro@online.no>
    Re: need Regular Expression to remove all non-numerical <vetro@online.no>
    Re: need Regular Expression to remove all non-numerical <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: need Regular Expression to remove all non-numerical <vetro@online.no>
    Re: need Regular Expression to remove all non-numerical (Anno Siegel)
    Re: need Regular Expression to remove all non-numerical <vetro@online.no>
    Re: Need to concatenate all files in a dir together int (Tony)
    Re: Need to concatenate all files in a dir together int <krahnj@acm.org>
        Need to concatenate all files in a dir together into on (Tony)
    Re: Need to concatenate all files in a dir together int <tadmc@augustmail.com>
    Re: Need to concatenate all files in a dir together int (Tony)
    Re: Need to concatenate all files in a dir together int <nobull@mail.com>
    Re: need to find word, and comment out next 5 lines (joe shaboo)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 18 Apr 2004 02:39:54 GMT
From: "g" <xft.phsm@vfryngrl.com>
Subject: Jessica Simpson showering on a texas beach 7788
Message-Id: <_Tlgc.23011$GN6.10154@fe2.columbus.rr.com>

Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach
Jessica Simpson showering on a texas beach






------------------------------

Date: Mon, 19 Apr 2004 08:29:37 GMT
From: Thomas =?ISO-8859-15?Q?G=F6tz?= <t.goetz@dkfz.de>
Subject: LWP::Simple and utf8 problem
Message-Id: <R5Mgc.2539219$iA2.293729@news.easynews.com>

Hi,

I want to retrieve a webpage that includes unicode characters using the
LWP::Simple module. But how can I tell LWP::Simple which coding it should
use as I haven't found anything concerning coding in the docs.

I use the following:

---
#!/usr/bin/perl -w

use strict;
use warnings;
use LWP::Simple;

my $file = "tmpfile";
my $url;

$url  = "http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?";
$url .= "db=Pubmed&retmax=500&id=15017969&retmode=xml";

getstore($url, $file);
exit;
-----

As it seems, the unicode characters are not correctly stored in the file. As
I'm not very familiar with utf8 stuff, I'd like to ask for a hint on how to
correctly store utf8-encoded webpages in a local file...!?

Tom



------------------------------

Date: 19 Apr 2004 07:19:10 -0700
From: vahu@novonordisk.com (Saya)
Subject: Need HELP with array and hash table comparison
Message-Id: <9e9517bf.0404190619.41b6060e@posting.google.com>

Hi, 

I need help/hints to accomplish the following.

Assume I have a varible $x looking something like this:

$x = "test test <a href="www.google.com">google</a> and some more text
here <a href="www.perl.com">perl</a>"

Now I use HTML::LinkExtor to find the a hrefs and call a replace
function:
$p = HTML::LinkExtor->new(\&replaceURL, "");
$p->parse($x);

The replaceURL function contains an array @safeLinkArr, consisting of
hrefs that need not to be done anything to. For instance lets say that
www.perl.com is a safe href so therefore it does not need anything
"done" to it.

How can I best run through the values in the hash against the values
in the safeLinkArr ? Is there a way I can say something like "in" and
make the comparison that way or how should the foreach or for loops
look like ???

Thx for any help provided 

/Saya

/


------------------------------

Date: Mon, 19 Apr 2004 10:53:18 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Need HELP with array and hash table comparison
Message-Id: <20040419104055.N21613@dishwasher.cs.rpi.edu>

On Mon, 19 Apr 2004, Saya wrote:

> Hi,
>
> I need help/hints to accomplish the following.
>
> Assume I have a varible $x looking something like this:
>
> $x = "test test <a href="www.google.com">google</a> and some more text
> here <a href="www.perl.com">perl</a>"

this has both Perl syntax errors (double quotes aren't escaped) and HTML
syntax errors (unless your website has local files named "www.google.com"
and "www.perl.com").  Please try to post actual code whenever possible.

> Now I use HTML::LinkExtor to find the a hrefs and call a replace
> function:
> $p = HTML::LinkExtor->new(\&replaceURL, "");
> $p->parse($x);
>
> The replaceURL function contains an array @safeLinkArr, consisting of
> hrefs that need not to be done anything to. For instance lets say that
> www.perl.com is a safe href so therefore it does not need anything
> "done" to it.
>
> How can I best run through the values in the hash against the values
> in the safeLinkArr ? Is there a way I can say something like "in" and
> make the comparison that way or how should the foreach or for loops
> look like ???


Your description is vague, but I *think* what you're asking for is how to
test each element of an array to see whether or not it exists in the hash?

Well, if the array values are keys to a hash, you just do this:
foreach (@array){
	if (exists $hash{$_}) {
		# %hash contains this element of @array;
	}
}

If, however, the array values are values to the hash, then you're
basically asking for the intersection of two lists.  This is covered in a
FAQ you can obtain from
perldoc -q intersection

my %count;
foreach (@array, values(%hash)){
	$count{$_}++;
}

my @inboth = grep { $count{$_} > 1 } keys %count;
my @inone = grep { $count {$_} == 1 } keys %count;

Now @inboth contains all the items that are in both the array and the
hash, and @inone contains all the items that are in one but not the other.

(Note, of course, that this assumes both the array and the hash contain
only unique values).

Hope this helps,
Paul Lalli



------------------------------

Date: Mon, 19 Apr 2004 19:09:07 +1000
From: "Robert" <robert@the.com>
Subject: need Regular Expression to remove all non-numerical 
Message-Id: <40839733$1@dnews.tpgi.com.au>


I'm trying to come up with a regex that will remove all non-numeric characters from a string.
ie: +01-876 003456

to: 01876003456

but am having an amazing amount of trouble - perhaps it's too late.
but if anyone can point me in theright direction, I'd be most gratefull.
thanks
Robert




------------------------------

Date: Mon, 19 Apr 2004 09:23:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: need Regular Expression to remove all non-numerical 
Message-Id: <lUMgc.20731$G_.2113@nwrddc02.gnilink.net>

Robert wrote:
> I'm trying to come up with a regex that will remove all non-numeric
> characters from a string. ie: +01-876 003456
>
> to: 01876003456

Please note, regular expressions don't "remove" anything.
Regular expressions "match" text, .... and then maybe the s() operator
replaces the matched text with some other text or the m() operator returns
true, etc..

> but am having an amazing amount of trouble -

What did you try? Show us your code.

> perhaps it's too late.
> but if anyone can point me in theright direction, I'd be most
> gratefull.

From "perldoc perlre":
            \D  Match a non-digit character

jue





------------------------------

Date: Mon, 19 Apr 2004 07:58:35 -0500
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: need Regular Expression to remove all non-numerical 
Message-Id: <MPG.1aed88f8eb2ac37598980b@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <40839733$1@dnews.tpgi.com.au>, robert@the.com says...
> 
> I'm trying to come up with a regex that will remove all non-numeric characters from a string.
> ie: +01-876 003456
> 
> to: 01876003456
> 
> but am having an amazing amount of trouble - perhaps it's too late.
> but if anyone can point me in theright direction, I'd be most gratefull.
> thanks
> Robert


$string =~ s/\D//g;  # remove all non-numeric chars


------------------------------

Date: Mon, 19 Apr 2004 11:28:24 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <Xns94D074BC9C3A4elhber1lidotechnet@62.89.127.66>

"Robert" <robert@the.com> wrote:

> 
> I'm trying to come up with a regex that will remove all
> non-numeric characters from a string. ie: +01-876 003456
> 
> to: 01876003456


$input =~ tr/0-9//cd;

 
> but am having an amazing amount of trouble - perhaps it's too
> late.


Too late? Too late for what?


-- 
Cheers,
Bernard


------------------------------

Date: Mon, 19 Apr 2004 11:43:58 +0200
From: Vetle Roeim <vetro@online.no>
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <m31xmk8fq9.fsf@quimby.dirtyhack.org>

* robert@the.com
> I'm trying to come up with a regex that will remove all non-numeric
> characters from a string.  ie: +01-876 003456
>
> to: 01876003456
>
> but am having an amazing amount of trouble - perhaps it's too late.
> but if anyone can point me in theright direction, I'd be most
> gratefull.

  Try this regular expression: s/[^\d]//g. I.e.:

    my $str = '+01-876 003456';
    $str =~ s/[^\d]//g;

  [^\d] means match all characters that are _not_ digits, and the /g
  specifies that the substitution should continue throughout the
  string.

  HTH.
  
-- 
#!/usr/bin/vr


------------------------------

Date: Mon, 19 Apr 2004 11:45:29 +0200
From: Vetle Roeim <vetro@online.no>
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <m3vfjw713a.fsf@quimby.dirtyhack.org>

* Vetle Roeim
> * robert@the.com
>> I'm trying to come up with a regex that will remove all non-numeric
>> characters from a string.  ie: +01-876 003456
>>
>> to: 01876003456
>>
>> but am having an amazing amount of trouble - perhaps it's too late.
>> but if anyone can point me in theright direction, I'd be most
>> gratefull.
>
>   Try this regular expression: s/[^\d]//g. I.e.:
>
>     my $str = '+01-876 003456';
>     $str =~ s/[^\d]//g;

  Eh... That could of course be "s/\D//g" instead.


[...]
-- 
#!/usr/bin/vr


------------------------------

Date: Mon, 19 Apr 2004 13:27:15 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <Xns94D088E2EA26Celhber1lidotechnet@62.89.127.66>

Vetle Roeim <vetro@online.no> wrote:

> * robert@the.com
>> I'm trying to come up with a regex that will remove all non-numeric
>> characters from a string.  ie: +01-876 003456
>>
>> to: 01876003456
>>
>> but am having an amazing amount of trouble - perhaps it's too late.
>> but if anyone can point me in theright direction, I'd be most
>> gratefull.
> 
>   Try this regular expression: s/[^\d]//g.I.e.:
                                          ^^^^^^


Don't you think that could be a little bit confusing for a newbie?


-- 
Cheers,
Bernard


------------------------------

Date: Mon, 19 Apr 2004 14:52:22 +0200
From: Vetle Roeim <vetro@online.no>
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <m31xmk6sft.fsf@quimby.dirtyhack.org>

* Bernard El-Hagin
> Vetle Roeim <vetro@online.no> wrote:
>
>> * robert@the.com
>>> I'm trying to come up with a regex that will remove all non-numeric
>>> characters from a string.  ie: +01-876 003456
>>>
>>> to: 01876003456
>>>
>>> but am having an amazing amount of trouble - perhaps it's too late.
>>> but if anyone can point me in theright direction, I'd be most
>>> gratefull.
>> 
>>   Try this regular expression: s/[^\d]//g.I.e.:
>                                           ^^^^^^
>
>
> Don't you think that could be a little bit confusing for a newbie?

  Um, yes. :D The code example should have cleared things up, though.


-- 
#!/usr/bin/vr


------------------------------

Date: 19 Apr 2004 13:01:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <c60ik3$3k0$1@mamenchi.zrz.TU-Berlin.DE>

Web Surfer  <raisin@delete-this-trash.mts.net> wrote in comp.lang.perl.misc:
> [This followup was posted to comp.lang.perl.misc]
> 
> In article <40839733$1@dnews.tpgi.com.au>, robert@the.com says...
> > 
> > I'm trying to come up with a regex that will remove all non-numeric
> characters from a string.
> > ie: +01-876 003456
> > 
> > to: 01876003456
> > 
> > but am having an amazing amount of trouble - perhaps it's too late.
> > but if anyone can point me in theright direction, I'd be most gratefull.
> > thanks
> > Robert
> 
> 
> $string =~ s/\D//g;  # remove all non-numeric chars

    $string =~ tr/0-9//cd;

does the same, but faster.

Anno


------------------------------

Date: Mon, 19 Apr 2004 15:29:23 +0200
From: Vetle Roeim <vetro@online.no>
Subject: Re: need Regular Expression to remove all non-numerical
Message-Id: <m3smf05c5o.fsf@quimby.dirtyhack.org>

* Anno Siegel
> Web Surfer  <raisin@delete-this-trash.mts.net> wrote in comp.lang.perl.misc:
>> [This followup was posted to comp.lang.perl.misc]
>> 
>> In article <40839733$1@dnews.tpgi.com.au>, robert@the.com says...
>> > 
>> > I'm trying to come up with a regex that will remove all non-numeric
>> characters from a string.
>> > ie: +01-876 003456
>> > 
>> > to: 01876003456
>> > 
>> > but am having an amazing amount of trouble - perhaps it's too late.
>> > but if anyone can point me in theright direction, I'd be most gratefull.
>> > thanks
>> > Robert
>> 
>> 
>> $string =~ s/\D//g;  # remove all non-numeric chars
>
>     $string =~ tr/0-9//cd;
>
> does the same, but faster.

  For anyone interested in _why_ it's faster, this post seems to
  explain it: <URL:http://tinyurl.com/2txz8>


-- 
#!/usr/bin/vr


------------------------------

Date: 19 Apr 2004 08:28:28 -0700
From: tsciortino@hotmail.com (Tony)
Subject: Re: Need to concatenate all files in a dir together into one file and  read the first 225 characters from each file into another file.
Message-Id: <bf5e5d95.0404190728.5f27f846@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<40833037.8B889B34@acm.org>...
> Tony wrote:
> > 
> > I am trying to concatenate all files in a directory together into one
> > file and read the first 225 characters of each file into one file as
> > sort of a summary file.
> > 
> > This does cat all file together into one bigfile
> > 
> > my $directory = "c:\\myfiles";
> > my $bigfile =c:\\bigfile.txt";
> > 
> > opendir (DIR, $directory) or die $!;
> > @ARGV = readdir(DIR);
> > 
> > chdir( $directory ) or die $!; #Need to do this readdir has just
> > filename
> > @ARGV = grep( -f, @ARGV);
> > 
> > foreach (@ARGV) {
> >     local $/ ;
> >     open OUT,">$bigfile" or die $!;
> >     while( <> ){
> >         print OUT $_, "\n";
> >         }
> >     }
> > close OUT;
> > closedir(DIR)
> > 
> > Now this does read the first 225 characters from each file but I need
> > to put it into a single file, not to STDOUT and I can not get the two
> > to run together in the same script.
> > 
> > chdir( $directory ) or die $!;
> > @ARGV = grep( -f, @ARGV);
> > $files = shift(@ARGV);
> > while (<>) {
> > open(INFILE,"<$files") or die "Can't open: $!\n";
> > read(INFILE,$buff,225,0);
> > print "$buff\n";
> > }
> > close(INFILE);
> 
> 
> This should work (untested):
> 
> my $directory = 'c:/myfiles';
> my $bigfile   = 'c:/bigfile.txt';
> my $summary   = 'c:/summary.txt';
> 
> opendir DIR, $directory or die $!;
> @ARGV = map "$directory/$_", grep -f, readdir DIR;
> 
> open OUT, '>', $bigfile or die "Cannot open $bigfile: $!";
> open SUM, '>', $summary or die "Cannot open $summary: $!";
> 
> $/ = \225;
> while ( <> ) {
>     print SUM if $. == 1;
>     print OUT;
>     close ARGV if eof;
>     }
> 
> 
> 
> John

Here is the final answer for reading the first 225 characters from
each file in my directory and creating a file from that.

open OUTF,">$sum" or die "Can't open file $!"; 
 foreach my $files (@ARGV) { 
  open(INFILE, $files); 
  read(INFILE,$buff,225,0); 
  print OUTF $buff, "\n"; 
}


------------------------------

Date: Mon, 19 Apr 2004 01:50:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Need to concatenate all files in a dir together into one file and  read the first 225 characters from each file into another file.
Message-Id: <40833037.8B889B34@acm.org>

Tony wrote:
> 
> I am trying to concatenate all files in a directory together into one
> file and read the first 225 characters of each file into one file as
> sort of a summary file.
> 
> This does cat all file together into one bigfile
> 
> my $directory = "c:\\myfiles";
> my $bigfile =c:\\bigfile.txt";
> 
> opendir (DIR, $directory) or die $!;
> @ARGV = readdir(DIR);
> 
> chdir( $directory ) or die $!; #Need to do this readdir has just
> filename
> @ARGV = grep( -f, @ARGV);
> 
> foreach (@ARGV) {
>     local $/ ;
>     open OUT,">$bigfile" or die $!;
>     while( <> ){
>         print OUT $_, "\n";
>         }
>     }
> close OUT;
> closedir(DIR)
> 
> Now this does read the first 225 characters from each file but I need
> to put it into a single file, not to STDOUT and I can not get the two
> to run together in the same script.
> 
> chdir( $directory ) or die $!;
> @ARGV = grep( -f, @ARGV);
> $files = shift(@ARGV);
> while (<>) {
> open(INFILE,"<$files") or die "Can't open: $!\n";
> read(INFILE,$buff,225,0);
> print "$buff\n";
> }
> close(INFILE);


This should work (untested):

my $directory = 'c:/myfiles';
my $bigfile   = 'c:/bigfile.txt';
my $summary   = 'c:/summary.txt';

opendir DIR, $directory or die $!;
@ARGV = map "$directory/$_", grep -f, readdir DIR;

open OUT, '>', $bigfile or die "Cannot open $bigfile: $!";
open SUM, '>', $summary or die "Cannot open $summary: $!";

$/ = \225;
while ( <> ) {
    print SUM if $. == 1;
    print OUT;
    close ARGV if eof;
    }



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 18 Apr 2004 07:30:50 -0700
From: tsciortino@hotmail.com (Tony)
Subject: Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file.
Message-Id: <bf5e5d95.0404180630.33ee921d@posting.google.com>

I am trying to concatenate all files in a directory together into one
file and read the first 225 characters of each file into one file as
sort of a summary file.

This does cat all file together into one bigfile

my $directory = "c:\\myfiles";
my $bigfile =c:\\bigfile.txt";

opendir (DIR, $directory) or die $!;
@ARGV = readdir(DIR);

chdir( $directory ) or die $!; #Need to do this readdir has just
filename
@ARGV = grep( -f, @ARGV);

foreach (@ARGV) {
    local $/ ;
    open OUT,">$bigfile" or die $!;
    while( <> ){
        print OUT $_, "\n";
        }
    }
close OUT;
closedir(DIR)

Now this does read the first 225 characters from each file but I need
to put it into a single file, not to STDOUT and I can not get the two
to run together in the same script.

chdir( $directory ) or die $!;
@ARGV = grep( -f, @ARGV);
$files = shift(@ARGV);
while (<>) {
open(INFILE,"<$files") or die "Can't open: $!\n";
read(INFILE,$buff,225,0);
print "$buff\n";
}
close(INFILE);

Many thanks for any help..


------------------------------

Date: Sun, 18 Apr 2004 14:20:58 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file.
Message-Id: <slrnc85l8q.1mn.tadmc@magna.augustmail.com>

Tony <tsciortino@hotmail.com> wrote:
> I am trying to concatenate all files in a directory together into one
> file and read the first 225 characters of each file into one file as
> sort of a summary file.
> 
> This does cat all file together into one bigfile


No it doesn't.

It stomps on $bigfile for each little file...


> my $directory = "c:\\myfiles";


If you use single quotes you won't have to remember to double backslashes:

   my $directory = 'c:\myfiles';

If you use sensible slashes, then you can use either kind of quotes:

   my $directory = "c:/myfiles";
or
   my $directory = 'c:/myfiles';



> my $bigfile =c:\\bigfile.txt";
              ^^
              ^^ where's the quote?


Please don't try and retype code.

Have you seen the Posting Guidelines that are posted here frequently?


> opendir (DIR, $directory) or die $!;
> @ARGV = readdir(DIR);
> 
> chdir( $directory ) or die $!; #Need to do this readdir has just
> filename
> @ARGV = grep( -f, @ARGV);
> 
> foreach (@ARGV) {
>     local $/ ;
>     open OUT,">$bigfile" or die $!;


$bigfile will contain ONLY the last file from @ARGV, which isn't
what you said it is doing.

So then, the code you have is not the code you've shown us.

We cannot help fix code that we cannot see...


> Now this does read the first 225 characters from each file but I need
> to put it into a single file, not to STDOUT


Then open() some other filehandle and print() to the other filehandle.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 18 Apr 2004 19:41:20 -0700
From: tsciortino@hotmail.com (Tony)
Subject: Re: Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file.
Message-Id: <bf5e5d95.0404181841.52d4795d@posting.google.com>

Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnc85l8q.1mn.tadmc@magna.augustmail.com>...
> Tony <tsciortino@hotmail.com> wrote:
> > I am trying to concatenate all files in a directory together into one
> > file and read the first 225 characters of each file into one file as
> > sort of a summary file.
> > 
> > This does cat all file together into one bigfile
> 
> 
> No it doesn't.
> 
> It stomps on $bigfile for each little file...
> 
> 
> > my $directory = "c:\\myfiles";
> 
> 
> If you use single quotes you won't have to remember to double backslashes:
> 
>    my $directory = 'c:\myfiles';
> 
> If you use sensible slashes, then you can use either kind of quotes:
> 
>    my $directory = "c:/myfiles";
> or
>    my $directory = 'c:/myfiles';
> 
> 
> 
> > my $bigfile =c:\\bigfile.txt";
>               ^^
>               ^^ where's the quote?
> 
> 
> Please don't try and retype code.
> 
> Have you seen the Posting Guidelines that are posted here frequently?
> 
> 
> > opendir (DIR, $directory) or die $!;
> > @ARGV = readdir(DIR);
> > 
> > chdir( $directory ) or die $!; #Need to do this readdir has just
> > filename
> > @ARGV = grep( -f, @ARGV);
> > 
> > foreach (@ARGV) {
> >     local $/ ;
> >     open OUT,">$bigfile" or die $!;
> 
> 
> $bigfile will contain ONLY the last file from @ARGV, which isn't
> what you said it is doing.
> 
> So then, the code you have is not the code you've shown us.
> 
> We cannot help fix code that we cannot see...
> 
> 
> > Now this does read the first 225 characters from each file but I need
> > to put it into a single file, not to STDOUT
> 
> 
> Then open() some other filehandle and print() to the other filehandle.



Ok, ok, sorry about trying to change things a little for the post but
I had named a couple files something I did not want to post. Will
never to that again. I just won't use such descriptive filenames.

So, with that said, here is the final part of the code I need to
finish.

my $outf = 'c:\mailme.txt';
foreach (@ARGV) {
    $files = shift(@ARGV);
    open(INFILE,"<$files") or die "Can't open: $!\n";
    open OUTF,">$outf" or die $!;
    read(INFILE,$buff,225,0);
    print OUTF $buff,"\n";
    print "$buff\n";
}
close(INFILE);

This code is supposed to read the first 225 characters from each file
in ARGV.
It seems to do just that in that print $buff does print just like
that. But when I try to print OUTF I only get one line. What am I
missing?


------------------------------

Date: 19 Apr 2004 09:03:44 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file.
Message-Id: <u9fzb04cnz.fsf@wcl-l.bham.ac.uk>

tsciortino@hotmail.com (Tony) writes:

> Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnc85l8q.1mn.tadmc@magna.augustmail.com>...
> > Tony <tsciortino@hotmail.com> wrote:
> > > 
> > > This does cat all file together into one bigfile
> > 
> > 
> > No it doesn't.
> > 
> > It stomps on $bigfile for each little file...

[ snip ]

> So, with that said, here is the final part of the code I need to
> finish.

[ code that still re-opens output file on each iteration ]

> What am I missing?

What Tad said.  Oh and you didn't close the output file.  This
probalby won't matter unless you try to re-read it before the script
terminates.

Also tsciortino@hotmail.com (Tony) writes:

> foreach (@ARGV) {
>     $files = shift(@ARGV);
      # do stuf...
> }

This is rather confused.  I'm sure you meant either...

  foreach my $files (@ARGV) {
      # do stuff...
  }

Or...
 
  while (@ARGV) {
      my $files = shift(@ARGV);
      # do stuff... 
  }

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: 19 Apr 2004 07:06:31 -0700
From: jshaboo@hotmail.com (joe shaboo)
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <f6d34657.0404190606.3ed7ce8f@posting.google.com>

OK, this works, and it is what I'm loosely going with since I can
understand it.

What I'm trying to do now is use this with a file that reads in an
array of domains. How can I write this into the script? and how are
the command line arguments handled?

 ./test.pl named.conf works if I hardcode in the domain named. What
about if I need multiple zone.com's passed in, for example file1 which
includes 10 domains.

test.pl

#!/usr/bin/perl

my $re = qr{test.com};
my $commenting = 0;

while (<>) {
    if (/$re/) {
     $commenting = 1;
     print "//";
     }
     print "//" if $commenting;
     print;
     $commenting = 0 if /^s*}/;
}
exit;

As you can see, I'm new to this, so hopefully these are easy
questions.

Joe.








Glenn Jackman <xx087@freenet.carleton.ca> wrote in message news:<slrnc7nrfc.stu.xx087@smeagol.ncf.ca>...
> joe shaboo <jshaboo@hotmail.com> wrote:
> [...]
> >  example
> >  
> >  zone "mydomain.com" {
> >      type master;
> >      file "path/to/zone"
> >      notify yes;
> >  }
> >  
> >  what I'd like to do
> >  
> >  // Domain commented out by `finger `logname` | grep real | awk '{print
> >  $7" "$8}'` on date.
> >  // zone "mydomain.com"
> >  //       type master;
> >  //       file "path/to/zone"
> >  //       notify yes;
> >  //}
> 
> Here's one approach:
> 
>     #!/usr/local/bin/perl
>     use strict;
>     use warnings;
> 
>     my $re = qr{domain2};
>     my $commenting = 0;
> 
>     while (<DATA>) {
>         if (/$re/) {
>             $commenting = 1;
>             print "// some useful comment\n";
>         }
>         print "//" if $commenting;
>         print;
>         $commenting = 0 if /^\s*}/;
>     }
>     exit;
> 
>     __DATA__
>     zone "domain1.com" {
>         type master;
>         file "path/to/zone"
>         notify yes;
>     }
>     zone "domain2.com" {
>         type master;
>         file "path/to/zone"
>         notify yes;
>     }
>     zone "domain3.com" {
>         type master;
>         file "path/to/zone"
>         notify yes;
>     }


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6418
***************************************


home help back first fref pref prev next nref lref last post