[24694] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6853 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 21:05:51 2004

Date: Tue, 10 Aug 2004 18:05:08 -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           Tue, 10 Aug 2004     Volume: 10 Number: 6853

Today's topics:
    Re: [OT] Perl Developers Needed for Open-Source ATC! (Peter J. Acklam)
    Re: catch error code from system() (J. Romano)
    Re: Expression Problem (Jay Tilton)
    Re: Joining 2 strings (Anno Siegel)
    Re: Joining 2 strings (Sim)
        nat table and perl problem (bjohnsme)
    Re: News::Scan question (Greg Bacon)
    Re: News::Scan question <mr@sandman.net>
    Re: News::Scan question <mr@sandman.net>
        passing param('something') through a function <me@example.com>
    Re: passing param('something') through a function <me@example.com>
    Re: passing param('something') through a function <me@example.com>
    Re: passing param('something') through a function <flavell@ph.gla.ac.uk>
    Re: passing param('something') through a function <segraves_f13@mindspring.com>
    Re: passing param('something') through a function <me@example.com>
    Re: passing param('something') through a function <flavell@ph.gla.ac.uk>
        pos and capture <l.heisler@utoronto.ca>
    Re: pos and capture <l.heisler@utoronto.ca>
    Re: pos and capture <pinyaj@rpi.edu>
        Reading next line, finding missing number in sequence (Pea)
    Re: Reading next line, finding missing number in sequen <jgibson@mail.arc.nasa.gov>
    Re: Reading next line, finding missing number in sequen <abodeman@yahoo.com>
    Re: Reading next line, finding missing number in sequen <abodeman@yahoo.com>
    Re: Reading next line, finding missing number in sequen <matthew.garrish@sympatico.ca>
    Re: split inconsistency- why? <uri.guttman@fmr.com>
    Re: split inconsistency- why? <nospam-abuse@ilyaz.org>
    Re: split inconsistency- why? <flavell@ph.gla.ac.uk>
    Re: Statistics for comp.lang.perl.misc <mr@sandman.net>
    Re: Statistics for comp.lang.perl.misc <mr@sandman.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Aug 2004 20:18:39 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: [OT] Perl Developers Needed for Open-Source ATC!
Message-Id: <wu06oo00.fsf@online.no>

aquila_deus@yahoo.co.uk (Aquila Deus) wrote:

> The project MrATC (Air Traffic Control) needs more Perl developers.
> We've done some discussion and begin to code and write doc, but
> there are only 2 developers now (and one is a perl noob - me).

Remember to take the year 10000 problem into account, because
unless you find a whole lot of full-time programmers that will
join you, it will take you several thousand years to get it done.

Just a tip.

Peter
(System administrator/developer, Oslo ATC, Norway)

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


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

Date: 10 Aug 2004 12:03:04 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Re: catch error code from system()
Message-Id: <b893f5d4.0408101103.7c362f72@posting.google.com>

eight02645999@yahoo.com (justme) wrote in message news:<c0837966.0408091830.5b738121@posting.google.com>...
> 
> i wrote a perl script that is supposed to run a java program.
> 
> my $cmd ="/usr/bin/java javaprog";
> system($cmd);
> 
> the java prog returns an error code if there is an error when the java prog runs
> how can i catch the return code of the java prog reliably ? 

   There are several ways (read "perldoc -f system" to find out what
some of them are).  One of the simplest ways is to check the $?
variable, like this:

      my $cmd ="/usr/bin/java javaprog";
      system($cmd);
      my $errorCode = $? >> 8;  # don't forget the ">> 8" part!
      print "The error-code from the command was $errorCode.\n";

   Hope this helps.  You might also want to read the "perldoc perlvar"
documentation and search for the "$?" variable for more advice.

   -- J.


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

Date: Tue, 10 Aug 2004 23:54:45 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Expression Problem
Message-Id: <41195ff6.269796867@news.erols.com>

Noname <Some.One@hotmail.com> wrote:

: Hi,
: I have input from STDIN like $Input="1-5,6,8,10-15";
: which actually needs to be interpreted as an 
: array=1,2,3,4,5,6,8,10,11,12,13,14,15
: how can it be done,

    use Set::IntSpan;
    my @array = Set::IntSpan ->new( $Input ) ->elements;



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

Date: 10 Aug 2004 19:52:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Joining 2 strings
Message-Id: <cfb92k$cl2$1@mamenchi.zrz.TU-Berlin.DE>

bowsayge  <bowsayge@nomail.afraid.org> wrote in comp.lang.perl.misc:
> Sim said to us:
> 
> [...]
> > Problems:
> > 1. I cannot join/ append the 3 lines on a single line. 
> [...]
> 
> This works for bowsayge:
> 
> while (scalar @lines) {

No need for "scalar" there.  The conditional of "while" is already in
scalar context (boolean, specifically).


>     print join " ", splice @lines, 0, 3;
>     print "\n";
> }

You could print the lines and the line feed in a single statement.  Then
"while" can become a statement modifier, and the whole thing a one-liner:

    print join( " ", splice @lines, 0, 3), "\n" while @lines;

Anno


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

Date: 10 Aug 2004 15:51:24 -0700
From: selena_kid@yahoo.com (Sim)
Subject: Re: Joining 2 strings
Message-Id: <82bbfd98.0408101451.69866dfa@posting.google.com>

I managed to solve the problem! It is very similar to the solution Jue
posted. Here's how it goes. I wish to thank everyone who has thought
through this problem. My MSN is jjsimz@hotmail.com. I am a college
Physics student, and if you have any physics question, I might be of a
little help. =)


#!/usr/bin/perl
use strict;

open (FILE, 'sample.out') or die "could not open 'sample.out'!!! ";
open (OUTPUTFILE, '>>output.out') or die "could not open
'output.out'!!! ";
while (<FILE>) {
        s/^\s*((.*\S)?)\s*$/$1/; #removes spaces before and after the
string
        print (OUTPUTFILE $_, ' ');
        if ($. % 3 == 0) {print (OUTPUTFILE "\n")}    
}
close FILE;
close OUTPUTFILE;


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

Date: 10 Aug 2004 11:29:07 -0700
From: bjohnsme@yahoo.com (bjohnsme)
Subject: nat table and perl problem
Message-Id: <f0c2b2d1.0408101029.389d25cb@posting.google.com>

I have a perl script that I use to mangle packets by hand rather than
using iptables to redirect for me.  When I'm not using the perl script
though, I want to have ipmasquerading turned on.  My problem is this:

My script runs fine so long as I don't ever run "iptables -t nat -F"
(or for that matter, anything that uses -t nat).  I'm sending packets
using Net::RawSock.

Once one of those commands are run, is there a way to undo them?  I've
tried stopping the service, but then running /etc/init.d/iptables
status still returns info.

How can I go about changing the rules so that it acts like a machine
without iptables running at all?  I set the default policies to
accept, but this is no help either.   Does anybody know if RawSock
does something funky when it sends out packets that could be
interfering with iptables?   Any thoughts would be greatly
appreciated.


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

Date: Tue, 10 Aug 2004 21:22:52 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: News::Scan question
Message-Id: <10hif5ceknapn85@corp.supernews.com>

In article <mr-9E44F5.23103708082004@individual.net>,
    Sandman  <mr@sandman.net> wrote:

: My situation is that I have downloaded the contents of a newsgroup
: from my server using 'suck'. I then run a perl script that will
: iterate this file and insert every post into a MySQL database.

Well, News::Scan is designed poorly and doesn't facilitate drop-in
addition of new sources. :-(

: The problem I am having is with headers, and I thought that
: News::Scan::Article could help me with that - but I can't understand
: how to use - if it even can be used in the way I want to use it.

Depending on your intent, using N::S::A (cue Twilight Zone theme)
may be overkill.  You may get more mileage out of using Mail::Internet.

Below is a typescript of an example I put together:

$ cat input.txt
From: Sandman <mr@sandman.net>
Newsgroups: comp.lang.perl.misc
Subject: News::Scan
 question
 1
Date: Sun, 08 Aug 2004 23:10:37 +0200
Xref: sn-us comp.lang.perl.misc:512246

Ok, I've been looking at the News::Scan package, and I can't get my head around
it.
 .
From: Sandman <mr@sandman.net>
Newsgroups: comp.lang.perl.misc
Subject: News::Scan
 question
 2
Date: Sun, 08 Aug 2004 23:10:37 +0200
Xref: sn-us comp.lang.perl.misc:512246

My situation is that I have downloaded the contents of a newsgroup from my
server using 'suck'. I then run a perl script that will iterate this file and
insert every post into a MySQL database.
 .
From: Sandman <mr@sandman.net>
Newsgroups: comp.lang.perl.misc
Subject: News::Scan
 question
 3
Date: Sun, 08 Aug 2004 23:10:37 +0200
Xref: sn-us comp.lang.perl.misc:512246

The problem I am having is with headers, and I thought that News::Scan::Article
could help me with that - but I can't understand how to use - if it even can be
used in the way I want to use it.
 .
From: Sandman <mr@sandman.net>
Newsgroups: comp.lang.perl.misc
Subject: News::Scan
 question
 4
Date: Sun, 08 Aug 2004 23:10:37 +0200
Xref: sn-us comp.lang.perl.misc:512246

Basically, this is how my script looks like:
 .

$ cat try
#! /usr/local/bin/perl

use warnings;
use strict;

use News::Scan;
use News::Scan::Article;

$/ = "\n.\n";

my $group = News::Scan->new(Period => 7);

while (<>) {
    if (open my $fh, "<", \$_) {
        local $/ = "\n";  # MailTools stuff needs this

        my $art = News::Scan::Article->new($fh, Modify => 0, $group);

        print $art->subject, "\n";
    }
    else {
        warn "$0: open: $!\n";
    }
}

$ ./try input.txt
News::Scan
 question
 1
News::Scan
 question
 2
News::Scan
 question
 3
News::Scan
 question
 4

$

Hope this helps,
Greg
-- 
 . . . if there's a way to shade the truth - particularly a negative
truth - the folks on Wall Street will find a way. They create more shade
than a cabana boy.
    -- Eric Fry


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

Date: Tue, 10 Aug 2004 23:45:18 +0200
From: Sandman <mr@sandman.net>
Subject: Re: News::Scan question
Message-Id: <mr-FCEDE2.23451810082004@individual.net>

In article <10hif5ceknapn85@corp.supernews.com>,
 gbacon@hiwaay.net (Greg Bacon) wrote:

> <lengthy script and explanation snipped>
>
> Hope this helps,
> Greg

Thanks! I'll try it out as soon as I can! :)

-- 
Sandman[.net]


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

Date: Tue, 10 Aug 2004 23:46:31 +0200
From: Sandman <mr@sandman.net>
Subject: Re: News::Scan question
Message-Id: <mr-4952B3.23463110082004@individual.net>

In article <i38Sc.19983$Jp6.17178@newsread3.news.atl.earthlink.net>,
 "Bill Segraves" <segraves_f13@mindspring.com> wrote:

> "Sandman" <mr@sandman.net> wrote in message
> news:mr-9E44F5.23103708082004@individual.net...
> > Ok, I've been looking at the News::Scan package, and I can't get my head
> around
> > it.
> <snip>
> 
> Surely, you're aware of Google. OTOH, if you were, you would have found
> examples of how the author uses New::Scan, e.g.,
> 
> http://search.cpan.org/src/GBACON/News-Scan-0.53/eg/

Yes, I've read through all of therse example scripts, but they seem to all be 
based on batch-processing a feed file from a usenet server, not something I can 
call upon at will on any given set of data.

Or am I missing something?

-- 
Sandman[.net]


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

Date: Tue, 10 Aug 2004 17:10:48 -0400
From: steve_f <me@example.com>
Subject: passing param('something') through a function
Message-Id: <t9eih0p45b8q2vs6jjjhhvufkrpkpti7br@4ax.com>

When using CGI.pm, I am getting funny results...

this works:

param('mkt') ?
    $html =~ s/%mkt%/param('mkt')/e :
        $html =~ s/%mkt%/us/;

but here:
$html =~ s/%menu%/make_menu($mkt)/e;

and here:
print $socket get_request($keyword, $mkt);

I need to set $mkt = param('mkt') or the function doesn't 
work...any ideas?

TIA


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

Date: Tue, 10 Aug 2004 17:17:02 -0400
From: steve_f <me@example.com>
Subject: Re: passing param('something') through a function
Message-Id: <loeih0t28nevmnb84hnussmkpe36mtma03@4ax.com>

On Tue, 10 Aug 2004 17:10:48 -0400, steve_f <me@example.com> wrote:

>When using CGI.pm, I am getting funny results...
>
>this works:
>
>param('mkt') ?
>    $html =~ s/%mkt%/param('mkt')/e :
>        $html =~ s/%mkt%/us/;
>
>but here:
>$html =~ s/%menu%/make_menu($mkt)/e;
>
>and here:
>print $socket get_request($keyword, $mkt);
>
>I need to set $mkt = param('mkt') or the function doesn't 
>work...any ideas?
>
>TIA

oh man...sorry...maybe I am wrong about this...maybe
my code is just buggy! ;-)


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

Date: Tue, 10 Aug 2004 17:26:55 -0400
From: steve_f <me@example.com>
Subject: Re: passing param('something') through a function
Message-Id: <r8fih0hh10m31icsvvr837cb645eu8dkdk@4ax.com>

ok...sorry for double posting to my own thread ;-)

can CGI.pm use both POST and GET together?
I think that was the problem...by this I mean using
POST and also adding a query string on the url

my_script.cgi?something=value


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

Date: Tue, 10 Aug 2004 23:15:58 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: passing param('something') through a function
Message-Id: <Pine.LNX.4.61.0408102304360.18072@ppepc56.ph.gla.ac.uk>

On Tue, 10 Aug 2004, steve_f wrote:

> can CGI.pm use both POST and GET together?
[...]
> my_script.cgi?something=value

Well, its documentation (which you've obviously already consulted 
before deciding to pose the question, right?) told you that it could.  
So what's your question, really?  The problem, as I see it, is that 
the underlying specifications don't clearly entitle one to use that.
So if it fails to work, it's not CGI.pm's fault for trying to offer 
the option, but the underlying specs for failing to guarantee that 
it'll work.

More to the point, what are you trying to achieve?  Maybe there's a 
better solution to your problem, that doesn't involve such iffy 
technical details.  That's often the best approach to such arcane 
questions of detail, IMHO.


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

Date: Tue, 10 Aug 2004 22:40:34 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: passing param('something') through a function
Message-Id: <C9cSc.10570$nx2.8410@newsread2.news.atl.earthlink.net>

"steve_f" <me@example.com> wrote in message
news:r8fih0hh10m31icsvvr837cb645eu8dkdk@4ax.com...
> can CGI.pm use both POST and GET together?

Yes. See the documentation, "MIXING POST AND URL PARAMETERS"

--
Bill Segraves




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

Date: Tue, 10 Aug 2004 19:19:41 -0400
From: steve_f <me@example.com>
Subject: Re: passing param('something') through a function
Message-Id: <cmlih05mfvdep2tp6t9m2vf7vg641v67uf@4ax.com>

On Tue, 10 Aug 2004 23:15:58 +0100, "Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote:

>On Tue, 10 Aug 2004, steve_f wrote:
>
>> can CGI.pm use both POST and GET together?
>[...]
>> my_script.cgi?something=value
>
>Well, its documentation (which you've obviously already consulted 
>before deciding to pose the question, right?) told you that it could.  
>So what's your question, really?  The problem, as I see it, is that 
>the underlying specifications don't clearly entitle one to use that.
>So if it fails to work, it's not CGI.pm's fault for trying to offer 
>the option, but the underlying specs for failing to guarantee that 
>it'll work.
>
>More to the point, what are you trying to achieve?  Maybe there's a 
>better solution to your problem, that doesn't involve such iffy 
>technical details.  That's often the best approach to such arcane 
>questions of detail, IMHO.

Sorry again...I should of read the documentation. What I was trying
to achieve is to send some options through the query and some through
the POST method.

So....basically config type options are attached to the query...well...maybe
I really could just use a hidden tag instead. I think I was thinking it was
fun to do both, but I guess I could make it easier for myself.

Thanks,

Steve


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

Date: Wed, 11 Aug 2004 00:28:29 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: passing param('something') through a function
Message-Id: <Pine.LNX.4.61.0408110022150.18119@ppepc56.ph.gla.ac.uk>

On Tue, 10 Aug 2004, steve_f wrote:

> So....basically config type options are attached to the 
> query...well...maybe I really could just use a hidden tag instead. I 
> think I was thinking it was fun to do both, but I guess I could make 
> it easier for myself.

You've still got the PATH_INFO available (for any server that supports 
the CGI specification - which AIUI excludes MS's IIS from 
consideration).

But this is a CGI issue, rather than a Perl language matter.  CGI.pm 
certainly supports that; but the underlying technology would be better 
discussed, if need be, on an appropriate CGI group, viz. 
comp.infosystems.www.authoring.cgi (beware the automoderation bot).

hope that helps


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

Date: Tue, 10 Aug 2004 18:58:04 GMT
From: "UToronto News" <l.heisler@utoronto.ca>
Subject: pos and capture
Message-Id: <I28v74.Jo3@campus-news-reading.utoronto.ca>


I have a question about capturing information from a regular expression
match

when i run

$string="the rain in spain falls mainly on the plain";
$searchpattern=".ain";

while ($string=~m/$searchpattern/g)
{
  $position=pos($string)-length($search);
  print "position=$position\n";
  pos($string)=$position+1;
}

-- this searches for all occurences of $search in $string, and prints out
the starting position of each
position=8
position=17
position=28
position=43


but when i run
while (($capture)=$string=~m/($searchpattern)/g)
{
  $position=pos($string)-length($searchpattern);
  print "position=$position : $capture\n";
  pos($string)=$position+1;
}

-- I am able to capture the match, but pos($string) is empty, resulting in
$position equal to 0-length($capture)
position=-4 : rain

When capturing the match, does the pos pointer reset?  Is there a way of
using this pointer with capture?

Thanks
Larry





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

Date: Tue, 10 Aug 2004 19:58:20 GMT
From: "LEH" <l.heisler@utoronto.ca>
Subject: Re: pos and capture
Message-Id: <I28xzq.LLo@campus-news-reading.utoronto.ca>

I sorted out how to get this working.
instead of capturing into a variable, I capture into the $1 and use that

ie
while($string=~/($searchpatten)/g)
{
  $position=pos($string)-length($searchpattern);
  print "position=$position: $1\n";
  pos($string)=$position+1;
}

this does work,  but I am still curious to know why my capturing into a
variable resets pos($string)

Larry








"UToronto News" <l.heisler@utoronto.ca> wrote in message
news:I28v74.Jo3@campus-news-reading.utoronto.ca...
>
> I have a question about capturing information from a regular expression
> match
>
> when i run
>
> $string="the rain in spain falls mainly on the plain";
> $searchpattern=".ain";
>
> while ($string=~m/$searchpattern/g)
> {
>   $position=pos($string)-length($search);
>   print "position=$position\n";
>   pos($string)=$position+1;
> }
>
> -- this searches for all occurences of $search in $string, and prints out
> the starting position of each
> position=8
> position=17
> position=28
> position=43
>
>
> but when i run
> while (($capture)=$string=~m/($searchpattern)/g)
> {
>   $position=pos($string)-length($searchpattern);
>   print "position=$position : $capture\n";
>   pos($string)=$position+1;
> }
>
> -- I am able to capture the match, but pos($string) is empty, resulting in
> $position equal to 0-length($capture)
> position=-4 : rain
>
> When capturing the match, does the pos pointer reset?  Is there a way of
> using this pointer with capture?
>
> Thanks
> Larry
>
>
>




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

Date: Tue, 10 Aug 2004 17:27:48 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: LEH <l.heisler@utoronto.ca>
Subject: Re: pos and capture
Message-Id: <Pine.SGI.3.96.1040810172630.23808B-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On Tue, 10 Aug 2004, LEH wrote:

>this does work,  but I am still curious to know why my capturing into a
>variable resets pos($string)
>
>> while (($capture)=$string=~m/($searchpattern)/g)

The problem is that saying

  (...) = $string =~ /pattern/g;

enforces *list* context on the pattern match, and a global pattern match
in list context matches as many times as possible, and afterwards, pos()
doesn't have a useful value.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
RPI Corporation Secretary   %  have long ago been overpaid?
http://japhy.perlmonk.org/  %  
http://www.perlmonks.org/   %    -- Meister Eckhart




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

Date: 10 Aug 2004 13:19:04 -0700
From: taralish@yahoo.com (Pea)
Subject: Reading next line, finding missing number in sequence
Message-Id: <f4bfa101.0408101219.178815c0@posting.google.com>

Hello,
I know this has been discussed before and I've tried some of the
solutions too.  But I've been unsuccessful so far.  I have a simple
text file of numbers, one on each line and just need a script that
will find the missing number.  Example of file:
1
2
3
5

My script:

open (FILE, "FILE.txt");
open (MISSING, ">Missing.txt");

while (<FILE>) {
   $currline = $_;
   $nxtline=$currline++ ;
   if ($_ != $nxtline) {
       print MISSING "Missing occurrence is $_  \n";   
   }
}

close FILE;
close MISSING;

This doesn't identify that 4 is missing.  Any ideas?
Thank you in advance,
Tara Pillion


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

Date: Tue, 10 Aug 2004 16:14:50 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Reading next line, finding missing number in sequence
Message-Id: <100820041614508489%jgibson@mail.arc.nasa.gov>

In article <f4bfa101.0408101219.178815c0@posting.google.com>, Pea
<taralish@yahoo.com> wrote:

> Hello,
> I know this has been discussed before and I've tried some of the
> solutions too.  But I've been unsuccessful so far.  I have a simple
> text file of numbers, one on each line and just need a script that
> will find the missing number.  Example of file:
> 1
> 2
> 3
> 5
> 
> My script:
> 
> open (FILE, "FILE.txt");
> open (MISSING, ">Missing.txt");
> 
> while (<FILE>) {
>    $currline = $_;
>    $nxtline=$currline++ ;
>    if ($_ != $nxtline) {
>        print MISSING "Missing occurrence is $_  \n";   
>    }
> }
> 
> close FILE;
> close MISSING;
> 
> This doesn't identify that 4 is missing.  Any ideas?

Yes. You have a logic error.

1. $currline = $_;   # this sets $currline to the value just read
2. $nxtline = $currline++; # this sets $nxtline to the same value
3. if( $_ != $nxtline ) {  # this compares $nxtline to the same value

In other words, $_ and $nxtline are always the same.

The postfix increment operator ($x++) returns the value _before_
incrementing. The prefix operator (++$x) returns the value _after_
incrementing. However, using the prefix version won't fix your problem,
either. You need to compare each line to one greater than the previous
line (untested):

my $expected = 1;
while(<FILE>) {
  if( $_ != $expected ) {
    print MISSING "Missing ...";
  }
  $expected = $_ + 1;
}


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

Date: Tue, 10 Aug 2004 18:22:40 -0500
From: "Brian Kell" <abodeman@yahoo.com>
Subject: Re: Reading next line, finding missing number in sequence
Message-Id: <opscjhv2ztz772u5@pc0938>

On 10 Aug 2004 13:19:04 -0700, Pea <taralish@yahoo.com> wrote:

> open (FILE, "FILE.txt");
> open (MISSING, ">Missing.txt");
>
> while (<FILE>) {
>    $currline = $_;
>    $nxtline=$currline++ ;
>    if ($_ != $nxtline) {
>        print MISSING "Missing occurrence is $_  \n";
>    }
> }
>
> close FILE;
> close MISSING;

In your script, you set $currline equal to $_, then set $nxtline equal to  
$currline, then increment $currline by one, then compare $_ to $nxtline.  
Since $nxtline gets its value from $currline (before $currline is  
incremented), and $currline gets its value from $_, $_ will always equal  
$nxtline.

What you need to do is write a textual description of how to solve the  
problem, then try to translate that into Perl.

Here's an idea, assuming the numbers in the file are in order from least  
to greatest, and no number is repeated:

1. Open the file.
2. Read the first line from the file.
3. Set $prev_line_num to the line number you read in step 2.
4. Read the next line from the file, if there is one.
5. Set $line_num to the line number you read in step 4.
6. Compare $line_num to ($prev_line_num + 1).
7. If they are different, then you're missing all numbers from  
($prev_line_num + 1) to ($line_num - 1).
8. Set $prev_line_num to the value of $line_num.
9. Go to step 4.

So in Perl:

#####

open FILE, "<FILE.txt" or die "Can't open FILE.TXT: $!\n";
open MISSING, ">Missing.txt" or die "Can't open Missing.txt: $!\n";

$prev_line_num = <FILE>;
while ($line_num = <FILE>) {
     if ($line_num != $prev_line_num + 1) {
         print MISSING "Missing occurrence is $_\n" for ($prev_line_num  
+ 1) .. ($line_num - 1);
     }
     $prev_line_num = $line_num;
}

close FILE;
close MISSING;

#####

In fact, you don't really need that if statement in there; the for loop is  
enough, since it will loop 0 times if there are no missing line numbers.  
But it's in there for clarity.

Brian

-----

($a='%Q$yW0se3%qhggfIi')=~s,([f-y]),qq;"\\c$1";,ege,@l=unpack'a5a5a*',$a;for$i(
@l){$$i.=sprintf"%lx",$_ for  
unpack'C*',$i;push@n,$$i;}$"=',',$_="\c`",$p=eval"
pack'VVN',@n",@b=unpack'C12',$p;$m=4054314,$a=96;(++$a,$m>>=1)&1?s@$@chr$a-!($a
%6-4)*32@e:$;while$m;@z=split m  
&&;for$j(@b){print$z[$j&15|($j>>=4,0)]for+z,j;}


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

Date: Tue, 10 Aug 2004 18:25:17 -0500
From: "Brian Kell" <abodeman@yahoo.com>
Subject: Re: Reading next line, finding missing number in sequence
Message-Id: <opscjh0fq0z772u5@pc0938>

On Tue, 10 Aug 2004 16:14:50 -0700, Jim Gibson <jgibson@mail.arc.nasa.gov>  
wrote:

> my $expected = 1;
> while(<FILE>) {
>   if( $_ != $expected ) {
>     print MISSING "Missing ...";
>   }
>   $expected = $_ + 1;
> }

But consider this file:

1
2
3
5
6
7
9
10

This script will print:

Missing 4...
Missing 5...
Missing 6...
Missing 7...
Missing 8...

(Assuming, of course, that you modified it to print the missing number.)

Brian

-----

($a='%Q$yW0se3%qhggfIi')=~s,([f-y]),qq;"\\c$1";,ege,@l=unpack'a5a5a*',$a;for$i(
@l){$$i.=sprintf"%lx",$_ for  
unpack'C*',$i;push@n,$$i;}$"=',',$_="\c`",$p=eval"
pack'VVN',@n",@b=unpack'C12',$p;$m=4054314,$a=96;(++$a,$m>>=1)&1?s@$@chr$a-!($a
%6-4)*32@e:$;while$m;@z=split m  
&&;for$j(@b){print$z[$j&15|($j>>=4,0)]for+z,j;}


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

Date: Tue, 10 Aug 2004 19:46:26 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Reading next line, finding missing number in sequence
Message-Id: <h7dSc.20263$Mq1.923325@news20.bellglobal.com>


"Pea" <taralish@yahoo.com> wrote in message
news:f4bfa101.0408101219.178815c0@posting.google.com...
> Hello,
> I know this has been discussed before and I've tried some of the
> solutions too.  But I've been unsuccessful so far.  I have a simple
> text file of numbers, one on each line and just need a script that
> will find the missing number.  Example of file:
> 1
> 2
> 3
> 5
>
> My script:
>

Where are strictures and warnings?

use strict;
use warnings;

> open (FILE, "FILE.txt");

Always check that your file even gets opened:

open(my $infile, '<', 'FILE.txt') or die "Could not open the input file:
$!";

> open (MISSING, ">Missing.txt");
>

Once again:

open(my $outfile, '>', 'Missing.txt') or die "Could not open the output
file: $!";

> while (<FILE>) {
>    $currline = $_;
>    $nxtline=$currline++ ;
>    if ($_ != $nxtline) {
>        print MISSING "Missing occurrence is $_  \n";
>    }
> }
>

In the above, you assign the value of the line to $currline, then add 1 and
assign it to $nxtline. You then test whether the value on the input line
equals the number you just incremented? This should fail for *all* cases
(i.e., 1+1 != 1, 2+1 != 2, etc.).:

my $cnt = 1;

while (my $num = <$infile>) {

   if ($num != $cnt) {

      print $outfile "Missing number(s): ";

      for (($num - ($num - $cnt)) .. ($num - 1)) {
         print $outfile "$_,";
      }

      print $outfile " at line $.\n";

      $cnt = $num;
   }

   $cnt++;
}


Matt




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

Date: Tue, 10 Aug 2004 15:13:37 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: split inconsistency- why?
Message-Id: <liwu06erha.fsf@fmr.com>

>>>>> "GJ" == Glenn Jackman <xx087@freenet.carleton.ca> writes:

  GJ> At 2004-08-10 11:06AM, Uri Guttman <uri@stemsystems.com> wrote:
  >> >>>>> "S" == Sara  <genericax@hotmail.com> writes:
  >> 
  S> I have yet to hear any valid reasons why this was a good design
  S> choice. Just a lot of the usual robotic "read the docs" jabber.  Tell
  S> ya what-
  >> 
  >> learn awk. split's default behavior follows awk's.

  GJ> Does it?  a2p begs to differ:

  GJ>     echo '
  GJ>         BEGIN {
  GJ>             s="this,is,a,comma,delimited,string,,"
  GJ>             split(s,a,/,/)
  GJ>             for (n in a) {print n ": " a[n]}
  GJ>             exit
  GJ>         }
  GJ>     ' | a2p -
 
  GJ> produces:
  GJ> ...
  GJ>     $S = 'this,is,a,comma,delimited,string,,';
  GJ>     @a = split(/,/, $S, 9999);
  GJ>     foreach $n ($[ .. $#a) {
  GJ>         print $n . ': ' . $a[$n];
  GJ>     } 

  GJ> Not Perl's default split behaviour.

you seem to be right there. my serious awk days are many moons ago. but
i did test awk (gawk really) just now and it does trim leading fields
which is what split ' ' does too. perldoc -f split does say that 
split ' ' emulates awk and deletes leading empty fields.

in any case the OP wanted to know why the default is to delete trailing
empty fields and few addressed the why and most said rtfm. so there was
a major communucation breakdown here and moronzilla wasn't involved for
a change. the docs don't address the why of this (other than the ' '
emulation of awk).

uri





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

Date: Tue, 10 Aug 2004 23:11:54 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: split inconsistency- why?
Message-Id: <cfbknq$2usu$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Tad McClellan 
<tadmc@augustmail.com>], who wrote in article <slrnchhsup.4b6.tadmc@magna.augustmail.com>:
> > Contract huh? With my legal-eagle hat on, a contract requires a
> > "meeting of the minds". 

> If you agree to call the function, then there _has_ been a
> meeting of the minds.
> 
> If you didn't want done what the function does, then you
> wouldn't call that function.

I think what you say does not make a lot of sense.  It assumes that
the documentation is correct and complete, and one is able to grok
what the documentation says.  Neither is true in the case of split().

During one phase of cleanup of Perl REx' semantic I managed to remove
about a dozen different quirks of split().  The remaining ones could
not be removed without a major change of semantic.

I tried to fix them nevertheless (by introduction of a pragma which
would make split() documentable and grokable), but this patch was not
accepted by the pumpking of the time...  Moreover, later it turned
out that I missed several more quirks...

Hope this helps,
Ilya


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

Date: Wed, 11 Aug 2004 00:20:58 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: split inconsistency- why?
Message-Id: <Pine.LNX.4.61.0408110015100.18119@ppepc56.ph.gla.ac.uk>

On Tue, 10 Aug 2004, Ilya Zakharevich wrote:

> <tadmc@augustmail.com>], who wrote in article 
> <slrnchhsup.4b6.tadmc@magna.augustmail.com>:
> 
> > If you agree to call the function, then there _has_ been a
> > meeting of the minds.
> > 
> > If you didn't want done what the function does, then you
> > wouldn't call that function.
> 
> I think what you say does not make a lot of sense. 

That depends on whether you are trying to design the language, or to 
use it.

> During one phase of cleanup of Perl REx' semantic I managed to remove
> about a dozen different quirks of split().  The remaining ones could
> not be removed without a major change of semantic.

Nevertheless, if the function is doing what it currently says on the 
tin, then any considerations of future cleanups are ultra vires, as 
far as a /user/ of the language is concerned.

No matter that you /could/ see a way to make it better/simpler/
more rational in the future.  With which I wouldn't presume to argue; 
but meantime, the users have what they're offered, with its relevant 
documentation, no?


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

Date: Tue, 10 Aug 2004 23:49:46 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <mr-EF1530.23494610082004@individual.net>

In article <slrnchhtbj.4b6.tadmc@magna.augustmail.com>,
 Tad McClellan <tadmc@augustmail.com> wrote:

> >> ;; > What does your question have to do with the statistics 
> >> ;; > for comp.lang.perl.misc?
> >> ;;  
> >> ;;  1. It concerns News::Scan, the modules used to generate the statistics.
> >> 
> >> Yes, and?
> > 
> > What kind of answer are you looking for?
> 
> 
> The subject of a post is kinda expected to align with the Subject of
> the post.

Ok, so what did your post have to do with the statistics for 
comp.lang.perl.misc? Why didn't you change it to "Me Trolling Sandman"?

> >> ;;  2. It is directed at Greg, the author of News::Scan, and the author of
> >> ;;     the statistics.
> >> 
> >> That's what email is for.
> > 
> > clp.misc aren't for perl discussions/help any more?
> 
> News groups are, well, *groups*. Greg is not a group, though he
> may be a member of the group.

I am not a group either - why aren't you mailing me with your comments?

> Putting "Greg" at the beginning of your post does not "direct" it
> to Greg.

Of course it does.

> Posting to a newsgroup directs it to the group.

Incorrect.

> Email can be used to direct a message to a particular individual.

Email could also be used to direct a message to a particular group.

> > You don't seem to have a point with your post - 
> 
> You didn't follow netiquette (where the Subject reflects the actual subject).

Incorrect.

> > why did you post it?
> 
> On the off chance that you would like to avoid appearing rude 
> in the future perhaps?

So you showed an example?

Look, go troll someone else - I'm here only for the perl discussion.

-- 
Sandman[.net]


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

Date: Tue, 10 Aug 2004 23:51:20 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <mr-8DC25B.23512010082004@individual.net>

In article <Yg5Sc.39$EQ5.37@nwrddc03.gnilink.net>,
 "Jürgen Exner" <jurgenex@hotmail.com> wrote:

> >> Then the Subject header should say something about News::Scan.
> >
> > My original post, the one I wanted Greg to view, did exactly that.
> 
> It did not. And it still says "Statistics for comp.lang.perl.misc" and
> nothing about News::Scan.

As does yours.

> >> Please help us keep threads threaded, don't put things unrelated to
> >> the Subject into the thread.
> >
> > I replied to a post, I didn't create the thread.
> 
> You replied with a request that had nothing to do with the statistics for
> comp.lang.perl.misc.

What are you replying to, and what does that have to do with the statistics of 
cpl.misc? Surely you're not expected to be held at any other standard than the 
one you're trying to push on others?

> > My reply wasdirected to a specific poster.
> 
> Then why did you send it to thousands of people instead of to him?

For the same reason you just sent your reply to thousands of people instead of 
just me.

-- 
Sandman[.net]


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

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 6853
***************************************


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