[30643] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1888 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 30 00:09:53 2008

Date: Mon, 29 Sep 2008 21:09:14 -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, 29 Sep 2008     Volume: 11 Number: 1888

Today's topics:
    Re: Download files script. <rich@example.net>
    Re: file locks and a counter <richard@example.invalid>
    Re: file locks and a counter <john@castleamber.com>
    Re: file locks and a counter <jurgenex@hotmail.com>
    Re: Help: Duplicate and Unique Lines Problem <mgjv@tradingpost.com.au>
        Help: Match Error <openlinuxsource@gmail.com>
    Re: Help: Match Error <jurgenex@hotmail.com>
    Re: Help: Match Error <openlinuxsource@gmail.com>
    Re: Help: Match Error <someone@example.com>
    Re: Help: Match Error <openlinuxsource@gmail.com>
    Re: Help: Match Error <mgjv@tradingpost.com.au>
        Help: Process many files at the same time <openlinuxsource@gmail.com>
    Re: Help: Process many files at the same time <jurgenex@hotmail.com>
    Re: Help: Process many files at the same time <openlinuxsource@gmail.com>
    Re: Object Oriented Perl questions <sun_tong_001@users.sourceforge.net>
    Re: Perl Strings vs FileHandle xhoster@gmail.com
    Re: Perl Strings vs FileHandle <tim@burlyhost.com>
    Re: Perl Strings vs FileHandle <someone@example.com>
    Re: Perl Strings vs FileHandle <tim@burlyhost.com>
    Re: Repeating characters <jwcarlton@gmail.com>
    Re: use Class::Std :ATTR <sun_tong_001@users.sourceforge.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Sep 2008 23:46:44 GMT
From: Rich Grise <rich@example.net>
Subject: Re: Download files script.
Message-Id: <pan.2008.09.29.23.46.38.460910@example.net>

On Sun, 28 Sep 2008 03:29:26 -0700, mathaios wrote:

> Hi.
> I want to install a script in my website  for the visitors to be able
> to download files.

Why not just link to it, and let them click "save to disk"?

Cheers!
Rich



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

Date: 30 Sep 2008 00:26:40 GMT
From: Richard Nixon <richard@example.invalid>
Subject: Re: file locks and a counter
Message-Id: <low3lojy1sy5$.1h73jkamv7fgh.dlg@40tude.net>

On 29 Sep 2008 21:46:19 GMT, xhoster@gmail.com wrote:

> dialup1@copper.net wrote:

>> sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT)         or die $!;
>>
>> do they have a better program?
> 
> That depends.  I tend to think that all sub-values of "broken" are
> equal, but sometimes some things can be more broken than others.
> 
> The current code has a race condition.  The change detects the race
> condition, but upon detecting it it aborts rather than recovering.
> Maybe:
> 
> sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT) or
>                             ($!{EEXIST} and redo) or die $!;
> 
> However, that still seems to have the problem that if the lock attempt
> times out, it proceeds as if the lock was obtained even though it hasn't
> been.
> 
> Xho

Thanks, Xho

Is it the difference between between having the occasional one go uncounted
as opposed to screwing up the whole thing?

I don't think this is a script that I can get far with with my own machine:

F:\gfortran\source>perl gary1.pl
Content-type: text/html

No such file or directory at gary1.pl line 230.

How do you keep track of line numbers with a longer perl script?  What I
did before was put a line somewhere like
some where;
and then the compiler would tell me which line had an error.  Then I would
move it closer to line 230.  Is there a better way?

-- 
Richard Milhous Nixon

All kings is mostly rapscallions.
~~ Mark Twain


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

Date: 30 Sep 2008 01:01:21 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: file locks and a counter
Message-Id: <Xns9B28CBAE61DEAcastleamber@130.133.1.4>

Richard Nixon <richard@example.invalid> wrote:

> How do you keep track of line numbers with a longer perl script?  What
> I did before was put a line somewhere like
> some where;
> and then the compiler would tell me which line had an error.  Then I
> would move it closer to line 230.  Is there a better way?

How about an editor that let you jump to line 230? (TextPad for example), 
or an editor that captures the messages from Perl and let you jump to the 
line with the (supposed) error via the captured messages?

-- 
John    http://johnbokma.com/ - Hacking & Hiking in Mexico

Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html


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

Date: Mon, 29 Sep 2008 18:21:59 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: file locks and a counter
Message-Id: <3iv2e4552nre9br0ls0s7i8qc0v01818ie@4ax.com>

Richard Nixon <richard@example.invalid> wrote:
>How do you keep track of line numbers with a longer perl script?  What I
>did before was put a line somewhere like
>some where;
>and then the compiler would tell me which line had an error.  Then I would
>move it closer to line 230.  Is there a better way?

What about just jumping to line 230?
- In EMACS M-x goto-line 230. Besides, the current line number is always
indicated in the status line.
- I vi I believe it's :230 but my vi is _very_ rusty.
- Heck, even Notepad has a Goto Line functionality.

What editor are you using that it doesn't know about line numbers?

jue


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

Date: Tue, 30 Sep 2008 08:03:25 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Help: Duplicate and Unique Lines Problem
Message-Id: <dbjrbg.gbd.ln@news.heliotrope.home>

On Mon, 29 Sep 2008 16:59:28 +0100,
	RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
>
> RedGrittyBrick wrote:

> P.S. For large amounts of data I'd prefer
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> my %seen;
> my @uniq;
> for(<DATA>) {
>    chomp;
>    if (/(\w+\s+\w+\s+)/) {
>      push @uniq, "$1\n" unless $seen{$1}++;
>    }
> }
> print sort @uniq;

Wouldn't it be better to use while(<DATA>){} (or one of the equivalent
forms listed in perlop), as for() builds a list? Or is this no longer
the case? 

Martien

PS. I couldn't find anything in the delta documents, since 5.6, about
foreach having changed this behaviour, but then, there's a lot of
documentation, and I could easily have missed something.
-- 
                        | 
Martien Verbruggen      | Quick! Hire a teenager while they still know
                        | everything.
                        | 


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

Date: Tue, 30 Sep 2008 09:39:18 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: Match Error
Message-Id: <pan.2008.09.30.01.39.17.376257@gmail.com>

Hello,

Here's my codes to match the following strings:

while (<>)
{
  chomp;
  if (/\d+\s+dG = (\d+)\s+(.*)/)
  {
    print "$1\n";
    print "$2\n";
  }
}

And the string is like this.
97	dG = -40.9	cel-mir-41 MI0000012 Caenorhabditis elegans miR-41 stem-loop

However, when I run my script it outputs nothing.

Could you tell me what's going on?

Thank you very much.

Best Regards,

Amy


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

Date: Mon, 29 Sep 2008 19:32:31 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help: Match Error
Message-Id: <9t33e4p5jrr937djhug3fia53v9e4febfq@4ax.com>

Amy Lee <openlinuxsource@gmail.com> wrote:
>Hello,
>
>Here's my codes to match the following strings:
>
>while (<>)
>{
>  chomp;
>  if (/\d+\s+dG = (\d+)\s+(.*)/)
>  {
>    print "$1\n";
>    print "$2\n";
>  }
>}
>
>And the string is like this.
>97	dG = -40.9	cel-mir-41 MI0000012 Caenorhabditis elegans miR-41 stem-loop
>
>However, when I run my script it outputs nothing.
>
>Could you tell me what's going on?

The minus sign is not a digit.

jue


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

Date: Tue, 30 Sep 2008 10:51:18 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Match Error
Message-Id: <pan.2008.09.30.02.51.17.889212@gmail.com>

On Mon, 29 Sep 2008 19:32:31 -0700, Jürgen Exner wrote:

> Amy Lee <openlinuxsource@gmail.com> wrote:
>>Hello,
>>
>>Here's my codes to match the following strings:
>>
>>while (<>)
>>{
>>  chomp;
>>  if (/\d+\s+dG = (\d+)\s+(.*)/)
>>  {
>>    print "$1\n";
>>    print "$2\n";
>>  }
>>}
>>
>>And the string is like this.
>>97	dG = -40.9	cel-mir-41 MI0000012 Caenorhabditis elegans miR-41 stem-loop
>>
>>However, when I run my script it outputs nothing.
>>
>>Could you tell me what's going on?
> 
> The minus sign is not a digit.
> 
> jue
Thanks. And I have noticed that, however if I want to match 
dG = 30 and dG = -30, what RE should I take?
Use /dg =( | -)(\d+)/ ?

Amy


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

Date: Mon, 29 Sep 2008 19:51:34 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help: Match Error
Message-Id: <WugEk.334$Aa2.153@newsfe10.iad>

Amy Lee wrote:
> Hello,
> 
> Here's my codes to match the following strings:
> 
> while (<>)
> {
>   chomp;
>   if (/\d+\s+dG = (\d+)\s+(.*)/)
>   {
>     print "$1\n";
>     print "$2\n";
>   }
> }
> 
> And the string is like this.
> 97	dG = -40.9	cel-mir-41 MI0000012 Caenorhabditis elegans miR-41 stem-loop
> 
> However, when I run my script it outputs nothing.
> 
> Could you tell me what's going on?

\d matches numerical digits, it doesn't match either '-' or '.'.

Try /\d+\s+dG = (-?[\d.]+)\s+(.*)/ instead.




John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Tue, 30 Sep 2008 10:56:52 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Match Error
Message-Id: <pan.2008.09.30.02.56.51.557818@gmail.com>

On Mon, 29 Sep 2008 19:51:34 -0700, John W. Krahn wrote:

> Amy Lee wrote:
>> Hello,
>> 
>> Here's my codes to match the following strings:
>> 
>> while (<>)
>> {
>>   chomp;
>>   if (/\d+\s+dG = (\d+)\s+(.*)/)
>>   {
>>     print "$1\n";
>>     print "$2\n";
>>   }
>> }
>> 
>> And the string is like this.
>> 97	dG = -40.9	cel-mir-41 MI0000012 Caenorhabditis elegans miR-41 stem-loop
>> 
>> However, when I run my script it outputs nothing.
>> 
>> Could you tell me what's going on?
> 
> \d matches numerical digits, it doesn't match either '-' or '.'.
> 
> Try /\d+\s+dG = (-?[\d.]+)\s+(.*)/ instead.
> 
> 
> 
> 
> John
Thank you very much. You show me the way.

Amy


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

Date: Tue, 30 Sep 2008 13:00:46 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Help: Match Error
Message-Id: <uo4sbg.tko.ln@news.heliotrope.home>

On Tue, 30 Sep 2008 09:39:18 +0800,
	Amy Lee <openlinuxsource@gmail.com> wrote:
> Hello,
>
> Here's my codes to match the following strings:
>
>   if (/\d+\s+dG = (\d+)\s+(.*)/)

You're looking for 

    one or more digits,
    one or more whitespace characters,
    "dG = ",
    one or more digits ...

> And the string is like this.
> 97	dG = -40.9	cel-mir-41 MI0000012 Caenorhabditis elegans miR-41 stem-loop

You have here

    one or more digits (97)
    one or more whitespace characters
    "dG = "
    a minus....

Ah. That must be why it didn't match. A minus is not a digit. Neither,
BTW is the . in -40.9, so even if you fixed the minus problem, you would
still not get the whole number that you're interested in, I presume. If
all your numbers follow the same format, with optional - only, you could
try

    /\d+\s+dG = (-?\d+\.\d+)\s+(.*)/

If there are possible + signs, and if the fractional part is also
optional maybe this will work:

    /\d+\s+dG = ([+-]?\d+(?:\.\d+)?)\s+(.*)/

How generic you need to get depends on the format of that number in your
data, and I don't know that. I only have the one example.

Have a look at the entry in perlfaq4 with the title "How do I determine
whether a scalar is a number/whole/integer/float?"

# perldoc -q "determine.*number"

That entry has many regular expressions, one of which you probably can
use, if the sufggestions above aren't sufficient.

Martien
-- 
                        | 
Martien Verbruggen      | We are born naked, wet and hungry. Then
                        | things get worse.
                        | 


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

Date: Tue, 30 Sep 2008 11:26:09 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: Process many files at the same time
Message-Id: <pan.2008.09.30.03.26.08.292608@gmail.com>

Hello,

Here's my codes:

foreach $file (@ARGV)
{
  while (<>)
  {
    chomp;
    if (/(\d+)\s+dG = (-?[\d.]+)\s+(.*)/)
    {
      $total = $1;
      $name = $3; 
      s/.*//;
    }
    $g += tr/C//;
    $c += tr/G//;
  }
  $gc = $g+$c;
  $GC = $gc/$total;
  print "$name\t$GC\n";
}
Then I hope I can get a list of the result because I use "foreach" to
process many files I gave at the same time. However, It just output one
file and the output variable $CG is wrong. If I run this to process one
file, it could work well.

I don't know what's errors in there.

Could you tell me what's going on?

Thanks.

Amy


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

Date: Mon, 29 Sep 2008 20:44:09 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help: Process many files at the same time
Message-Id: <c083e4p4d8j13fp9a6rrm281p7nevebf94@4ax.com>

Amy Lee <openlinuxsource@gmail.com> wrote:
>Hello,
>
>Here's my codes:
>
>foreach $file (@ARGV)

Ok, you are looping through all command line arguments

>{
>  while (<>)

For each of those arguments you are reading lines from the keyboard
until the user submits an EOF.

Is that what you want?

jue


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

Date: Tue, 30 Sep 2008 11:56:41 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Re: Help: Process many files at the same time
Message-Id: <pan.2008.09.30.03.56.40.540740@gmail.com>

On Mon, 29 Sep 2008 20:44:09 -0700, Jürgen Exner wrote:

> Amy Lee <openlinuxsource@gmail.com> wrote:
>>Hello,
>>
>>Here's my codes:
>>
>>foreach $file (@ARGV)
> 
> Ok, you are looping through all command line arguments
> 
>>{
>>  while (<>)
> 
> For each of those arguments you are reading lines from the keyboard
> until the user submits an EOF.
> 
> Is that what you want?
> 
> jue
Thanks. the codes 
while (<>)
  {
    chomp;
    if (/(\d+)\s+dG = (-?[\d.]+)\s+(.*)/)
    {
      $total = $1;
      $name = $3; 
      s/.*//;
    }
    $g += tr/C//;
    $c += tr/G//;
  }
  $gc = $g+$c;
  $GC = $gc/$total;
  print "$name\t$GC\n";
can process one file per time and work well. So I suppose that I can make
a foreach loop to process many files reads from filenames. But it seems
not work. So I wonder what's wrong with the codes.

Could you tell me how to modify that?

Amy


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

Date: Mon, 29 Sep 2008 22:01:43 -0500
From: * Tong * <sun_tong_001@users.sourceforge.net>
Subject: Re: Object Oriented Perl questions
Message-Id: <PP2dnUBDpYYKC3zVnZ2dnUVZ_gydnZ2d@golden.net>

On Sat, 27 Sep 2008 05:44:08 -0500, brian d  foy wrote:

>>     24      use Scalar::Util qw(weaken);    # in 5.8 and later
> 
>> It runs like this:
>> 
>> $ oo-test.pl
>> Prototype mismatch: sub Animal::weaken ($) vs none at /usr/share/
>> perl/5.10/Exporter.pm line 66.
>>  at ./oo-test.pl line 25
> 
> 
>> - how can I fix the "Prototype mismatch" error?
> 
> What is your Perl version and who compiled it?

Sorry for responding late. Thanks for the reply and in the other thread 
too. 

I'm using the standard perl package available in Debian Testing:

$ apt-cache policy perl
perl:
  Installed: 5.10.0-14
  Candidate: 5.10.0-14
  Version table:
 *** 5.10.0-14 0
        300 http://gulus.usherbrooke.ca lenny/main Packages
         50 http://gulus.usherbrooke.ca unstable/main Packages
        100 /var/lib/dpkg/status

This is how it is compiled:

$ perl -V
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.26.1, archname=i486-linux-gnu-thread-multi
    uname='linux ninsei 2.6.26.1 #1 smp preempt sun aug 3 22:34:07 pdt 
2008 i686 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -
Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/
share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 -Dvendorprefix=/usr -
Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/
local -Dsitelib=/usr/local/share/perl/5.10.0 -Dsitearch=/usr/local/lib/
perl/5.10.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -
Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -
Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -
Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -
Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-
aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -
pipe -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/lib64
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.7.so, so=so, useshrplib=true, 
libperl=libperl.so.5.10.0
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP 
USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Sep 12 2008 18:25:27

The WeakRef is what I just installed from CPAN. 

$ cpan -O | grep -i Weak || echo no found
no found

Any comments? 

thanks

tong




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

Date: 29 Sep 2008 22:34:03 GMT
From: xhoster@gmail.com
Subject: Re: Perl Strings vs FileHandle
Message-Id: <20080929183406.271$HX@newsreader.com>

shadabh <mshadabh@gmail.com> wrote:
>
> Thanks for all your suggestions/comments. So what is your idea of
> using this method. is there an alternative at all??

Yes, many alternatives.  The easiest might be to use Sys::Mmap to make
the file look like a variable without having it all in memory at the same
time.  That would require no changes to the code you showed us.

Or you could translate all of your substr operations on the variable into
the equivalent combination of "seek" and "read" operations on a file
handle.

Or you could read the file in suitable sized chunks.  But I found your code
so hard to follow (and you didn't show how variables get initialized) that
I won't dig into the exact way to do that.

> because $parm_data could potentially contain GB's worth of data.

But that doesn't mean anything to us.  We don't know what computer you
are using.  Do you have GB worth of RAM to go along with it?  In other
words, do you actually have a problem?

> Suggestions to improve the method are welcome. BTW all your comments
> are good and have included in my code. TY

If you don't have enough RAM to use your current method and thus actually
have a problem, please post your new code with the improvements in place
and with the indents and such cleaned up so we can follow it, and showing
how variables get initialized.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Mon, 29 Sep 2008 15:36:23 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Perl Strings vs FileHandle
Message-Id: <LLcEk.783$2B7.509@newsfe12.iad>

shadabh wrote:

> On Sep 17, 12:39 pm, "John W. Krahn" <some...@example.com> wrote:
>> shadabh wrote:
>> > On Sep 6, 6:08 pm, "John W. Krahn" <some...@example.com> wrote:
>> >> shadabh wrote:
>> >>> Hi all,
>> >>> Just wanted to run this through Perl gurus to see if fit is
>> >>> correct?. I have a file that could possibly be 1GB in variable
>> >>> length EBCDIC data. I will read the file as EBCDIC data and based
>> >>> on some criteria split it into 100 different files which will add
>> >>> up to the 1GB. This way a particular copy book can be applied to
>> >>> easy of the split files. The approach I am using is a filehandle
>> >>> ( IO::FileHandle and $Strings), substr and write out to 100
>> >>> different files after applying the 'logic'. I will use two
>> >>> routine, one to read and one to write, I have tested this out
>> >>> with 100MB file and it works fine. The question though is there a
>> >>> memory limit to this, as we are using strings to break the files.
>> >>> Or is there an alternative way to do this? Comments, suggestions,
>> >>> improvements and alternatives will really help to design the
>> >>> code. thanks
>> >> You have to show us what "this" is first.  It is kind of hard to
>> >> make comments, suggestions, improvements and alternatives to
>> >> something that we cannot see.
>>
>> >> John
>> >> --
>> >> Perl isn't a toolbox, but a small machine shop where you
>> >> can special-order certain sorts of tools at low cost and
>> >> in short order.                            -- Larry Wall- Hide
>> >> quoted text -
>>
>> >> - Show quoted text -
>>
>> > Sure. Here is what I meant by 'this way'. Please comment. Thanks
>>
>> > while ($raw_data) {
>>
>> You don't modify $raw_data inside the loop so there is no point in
>> testing it every time through the loop.
>>
>> > $var_len=$INIT_LEN+$AC_NUM_LENGTH;
>>
>> my $var_len = $INIT_LEN + $AC_NUM_LENGTH;
>>
>> > $val = substr $raw_data,$var_len,4;
>> > $asc_string = $val;
>>
>> my $asc_string = substr $raw_data, $var_len, 4;
>>
>> > eval '$asc_string =~ tr/\000-\377/' . $cp_037 . '/';
>> > # open(OUTF, '>>ebcdic_ID.txt');
>> > # #print OUTF $var_len, $asc_string, "\n";
>> > # close OUTF;
>> > open(PARM, '<TSY2_PARM.par') || die("Could not open the
>> > parammeter file $PARM_FILE ! File read failed ..check iF file
>> > exits");
>>
>> You are opening 'TSY2_PARM.par' but your error message says you are
>> opening $PARM_FILE.  You should include the $! variable in the error
>> message so you know *why* it failed to open.
>>
>> open my $PARM, '<', 'TSY2_PARM.par' or die "Could not open
>> 'TSY2_PARM.par' $!";
>>
>> > $parm_data = <PARM>;
>>
>> You assign the same data to $parm_data every time so...
>>
>> > if (($parm_data =~ m!($asc_string)!g) eq 1) {
>>
>> your pattern will always match at the same place every time through
>> the loop so if the pattern is present you have an infinite loop.  You
>> are not using the contents of $1 so the parentheses are superfluous. 
>> The comparison test to the string '1' is superfluous.
>>
>> if ( $parm_data =~ /$asc_string/g ) {
>>
>> > $COPYBOOK_LEN = substr $parm_data,length($`)+4,4;
>>
>> The use of $` is discouraged as it slows down *all* regular
>> expressions in your program.
>>
>> my $COPYBOOK_LEN = substr $parm_data, $-[ 0 ] + 4, 4;
>>
>> > print $COPYBOOK_LEN;
>> > close (PARM);
>> > $OUT_DATAFILE = 'EBCDIC_'.$asc_string.'.txt';
>> > $RECORD_LEN= $COPYBOOK_LEN+$HEADER_DATA;
>> > open(OUTF, ">>$OUT_DATAFILE")|| die("Could not open file. File
>> > read failed ..check id file exits");
>>
>> open my $OUTF, '>>', $OUT_DATAFILE or die "Could not open
>> '$OUT_DATAFILE' $!";
>>
>> > print OUTF substr $raw_data, $INIT_LEN, $RECORD_LEN;
>> > close OUTF;
>> > $INIT_LEN = $INIT_LEN + $RECORD_LEN;
>> > print $INIT_LEN;
>> > print $var_len;
>> > }
>> > else {
>> > print 'End of file reached or copy book is not a part of the
>> > loading process', "\n";
>> > exit 0;
>> > }
>> > }
>>
>> So, to summarise:
>>
>> open my $PARM, '<', 'TSY2_PARM.par' or die "Could not open the
>> parammeter file 'TSY2_PARM.par' $!";
>> my $parm_data = <$PARM>;
>> close $PARM;
>>
>> while ( 1 ) {
>>
>> my $var_len = $INIT_LEN + $AC_NUM_LENGTH;
>> my $asc_string = substr $raw_data, $var_len, 4;
>> eval '$asc_string =~ tr/\000-\377/' . $cp_037 . '/';
>>
>> if ( $parm_data =~ /\Q$asc_string\E/g ) {
>>
>> my $COPYBOOK_LEN = substr $parm_data, $-[ 0 ] + 4, 4;
>> my $OUT_DATAFILE = "EBCDIC_$asc_string.txt";
>> my $RECORD_LEN   = $COPYBOOK_LEN + $HEADER_DATA;
>>
>> open my $OUTF, '>>', $OUT_DATAFILE or die "Could not open
>> '$OUT_DATAFILE' $!";
>> print $OUTF substr $raw_data, $INIT_LEN, $RECORD_LEN;
>> close $OUTF;
>>
>> $INIT_LEN += $RECORD_LEN;
>> print $COPYBOOK_LEN, $INIT_LEN, $var_len;
>> }
>> else {
>> print "End of file reached or copy book is not a part of the
>> loading process\n";
>> last;
>> }
>> }
>>
>> exit 0;
>>
>> __END__
>>
>> John
>> --
>> Perl isn't a toolbox, but a small machine shop where you
>> can special-order certain sorts of tools at low cost and
>> in short order.                            -- Larry Wall
> 
> Thanks for all your suggestions/comments. So what is your idea of
> using this method. is there an alternative at all??
> because $parm_data could potentially contain GB's worth of data.
> Suggestions to improve the method are welcome. BTW all your comments
> are good and have included in my code. TY
> 
> Shadab

You said that "$parm_data could potentially contain GB's worth of data",
in which case, the below:

my $parm_data = <$PARM>;

Is going to kill your resources and probably even crash/overload the
system.  You need to do a while on the <PARM> file handle and step
through it per line (instead of reading it into a string or array
first).  You can cut out the middle man that way, too.  Otherwise you
are reading a potentially huge amount of data into a string (into
memory) and then trying to parse it.  That is always bad.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 29 Sep 2008 16:29:54 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perl Strings vs FileHandle
Message-Id: <SxdEk.8$kc.4@newsfe12.iad>

Tim Greer wrote:
> 
> You said that "$parm_data could potentially contain GB's worth of data",
> in which case, the below:
> 
> my $parm_data = <$PARM>;
> 
> Is going to kill your resources and probably even crash/overload the
> system.  You need to do a while on the <PARM> file handle and step
> through it per line (instead of reading it into a string or array
> first).  You can cut out the middle man that way, too.  Otherwise you
> are reading a potentially huge amount of data into a string (into
> memory) and then trying to parse it.  That is always bad.

In that context the size of data read is defined by the value of $/ 
which defaults to "\n" and the OP is working with "text" files so each 
record is probably not that large.


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Mon, 29 Sep 2008 20:59:01 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Perl Strings vs FileHandle
Message-Id: <9uhEk.1613$YN5.1209@newsfe03.iad>

John W. Krahn wrote:

> Tim Greer wrote:
>> 
>> You said that "$parm_data could potentially contain GB's worth of
>> data", in which case, the below:
>> 
>> my $parm_data = <$PARM>;
>> 
>> Is going to kill your resources and probably even crash/overload the
>> system.  You need to do a while on the <PARM> file handle and step
>> through it per line (instead of reading it into a string or array
>> first).  You can cut out the middle man that way, too.  Otherwise you
>> are reading a potentially huge amount of data into a string (into
>> memory) and then trying to parse it.  That is always bad.
> 
> In that context the size of data read is defined by the value of $/
> which defaults to "\n" and the OP is working with "text" files so each
> record is probably not that large.
> 
> 
> John

I've seen some pretty large files that use a new line as a separator. 
Maybe huge logs are being parsed?  I've seen Apache log files that
people want processed easily get up in the 1 - 2 gig range (of course,
they have to rotate or clear them once they get 2+ gigs in size). 
Anyway, as I said, I am only seeing the tail end of this thread.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Mon, 29 Sep 2008 18:17:36 -0700 (PDT)
From: Jason Carlton <jwcarlton@gmail.com>
Subject: Re: Repeating characters
Message-Id: <c6a8f39d-e299-4b6d-9dd8-04712d602ef9@i76g2000hsf.googlegroups.com>

On Sep 29, 5:42=A0pm, Hartmut Camphausen <Jus...@somewhere.de> wrote:
> Jason Carlton schrieb:
>
>
>
>
>
> > [...] but this is the only section that does any
> > replacements on this field:
>
> > $contents{'description'} =3D~ s/\r\n|\r|\n/ /g;
> > $contents{'description'} =3D~ s/\&/ and /g; =A0 =A0 =A0 =A0<--
> > $contents{'description'} =3D~ s/ =A0/ /g;
> > $contents{'description'} =3D~ s/</\&lt;/g; =A0 =A0 =A0 =A0 <--
> > $contents{'description'} =3D~ s/>/\&gt;/g; =A0 =A0 =A0 =A0 <--
> > $contents{'description'} =3D~ s/\*//g; =A0 =A0 =A0 =A0 =A0 =A0 <--
> > $contents{'description'} =3D~ s/ +$//;
> > $contents{'description'} =3D~ s/^\s+|\s+$//g;
> > $contents{'description'} =3D~ s/(.)\1{4,}/$1$1$1$1/g;
>
> > This is in a classifieds program. The other matches work, but
> > yesterday someone submitted this in the description field:
>
> > LARGE BIRD CAGE ASKING $200
> > FIRM ....>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> > It limited the .... to 4, but not the > or <
>
> Well ... how could it ;-)
>
> Have a look at what gets replaced before (lines marked with '<--').
>
> '<' and '>' are HTML-escaped with their respective entities and are thus
> not showing up literally in the string when the program reaches the last
> s///g statement.
>
> Hint: When checking results, have a look at the resulting *raw* data
> =A0 =A0 =A0 - use a text editor, not a web browser.
>
> hth + mfg, Hartmut
>
> --
> =A0 ------------------------------------------------
> Hartmut Camphausen =A0 =A0 =A0h.camp[bei]textix[punkt]de- Hide quoted tex=
t -
>
> - Show quoted text -


::smacking my head::

Well, DUH! Thanks for the help.


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

Date: Mon, 29 Sep 2008 22:04:30 -0500
From: * Tong * <sun_tong_001@users.sourceforge.net>
Subject: Re: use Class::Std :ATTR
Message-Id: <PP2dnUNDpYajCnzVnZ2dnUVZ_gydnZ2d@golden.net>

On Sun, 28 Sep 2008 05:09:27 -0700, Peter Scott wrote:

>   my %name_of :ATTR(:get<name>, :set<name>)

thanks. 

About the comma after get, the man pages doesn't have commas between :get 
and :set. But I've also see other places including the commas. What's the 
correct way?

thanks.

tong



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

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 V11 Issue 1888
***************************************


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