[11069] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4669 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 16 13:04:08 1999

Date: Sat, 16 Jan 99 10:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 16 Jan 1999     Volume: 8 Number: 4669

Today's topics:
    Re: calling a subroutine with variables (Tad McClellan)
        CGI error with C extensions in PERL <blackk@dial.oleane.com>
        cgi output with random banner webmaster@lifesprings.net
    Re: Downloading HTML files? (Rich)
    Re: filter href-links from web-page ? (Tad McClellan)
    Re: glob error <not@giving.it.out>
    Re: glob error (Ronald J Kimball)
    Re: glob error (Ronald J Kimball)
    Re: grep question <allan@due.net>
        HELP:  Writing Date/Time to Log <bucholtz@erols.com>
        JPL install difficulties glo83@yahoo.com
        Looking for CGI modules spadesmcgee@my-dejanews.com
        Looking for free Web Server with CGI <chrisl@hamptons.com>
        question on locale fernando@waycom.com.ar
    Re: question on locale <jhi@alpha.hut.fi>
    Re: Removing spaces from arrays... <allan@due.net>
    Re: Searching a string, with a headache (Tad McClellan)
    Re: Searching a string, with a headache <rick.delaney@home.com>
    Re: Stopping <ctrl>-c during perl Scripts (win32) (Bbirthisel)
    Re: The number of seconds since 1/1/1970 ? (Michael Fuhr)
    Re: Treating Strings as FILEHANDLES (Tad McClellan)
    Re: Treating Strings as FILEHANDLES (Ronald J Kimball)
    Re: Treating Strings as FILEHANDLES <rick.delaney@home.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 16 Jan 1999 08:58:06 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: calling a subroutine with variables
Message-Id: <ud9q77.him.ln@magna.metronet.com>

Andy Kaplan (andrew.kaplan@yale.edu) wrote:

: I'm not exactly a newbie at Perl, but I am self-taught and I know that there
: are gaping holes in my knowledge. Still, I've gotten pretty far with it I'd
: say, so I don't think my question is trivial. I have looked through the
: entire faq for something related, but can't find it:


   Very good. We appreciate it when folks make an attempt to find
   the answer themselves before posting.

   But it looks like you only used about 13% (based on line count)
   of the resources already installed on your hard drive.

   The FAQs are only part of the standard documentation.


: Basically, I want to use a variable to call a subroutine.


   Sounds like references would come in handy here.

   Start with perlref.pod.

   Might also want to have a look at perllol.pod and perldsc.pod.


: That is, I have,
: @variables = ("first", "second");

: And I have two subroutines, firstroutine and secondroutine. What I want is
: something like this:

: foreach $variable (@variables) {
:     if ($variable eq "first") {
:         &$variableroutine;
:     }
: }

: See? I want it to figure out the name of the appropriate subroutine on its
: own.

: How can I do this with Perl?


   Does this do it?

------------------------
#!/usr/bin/perl5.00502 -w
use strict;

my(%sub_xref) = (
   first  => \&firstroutine,
   second => \&secondroutine
);


my $variable = 'first';
&{$sub_xref{$variable}};

$variable = 'second';
&{$sub_xref{$variable}};


sub firstroutine { print "called firstroutine()\n" }

sub secondroutine { print "called secondroutine()\n" }
------------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 16 Jan 1999 18:02:50 +0100
From: "Black K" <blackk@dial.oleane.com>
Subject: CGI error with C extensions in PERL
Message-Id: <77qgt2$5mj$1@minus.oleane.net>

Hye and thanks for your help.

I call a C function from Perl ( XS ) to make an extension.
The Perl script works under shell, but the CGI fail to call the function
while it is running.
I did not install the extension yet.

Any clue about what I missed ? Do I have to install the extension beofre
being able to run the cgi?

Thanks a lot,

KB




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

Date: Sat, 16 Jan 1999 16:45:26 GMT
From: webmaster@lifesprings.net
Subject: cgi output with random banner
Message-Id: <77qfn5$ltu$1@nnrp1.dejanews.com>

What's the best way to include a random banner
script in the CGI output.
I use SSI pageheaders/footers on my html pages
with a call to the randome banner script.
That works fine on my html pages with SSI. But in
order to replace the
<!--%%banner%%--> in the cgi output,
should I require another script like I've done with
the jcooldate.pl or just
include the routines of the random imgae
script within the same cgi script that I'm using to
create the output.

It worked fine just
requiring the actual date script as shown below,
but when I tried the same
thing with my random banner script it wouldn't
finish outputting  the rest
of the header after it printed the banner.

Any thoughts would be appreciated.

-Jeff

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

sub PrintHeader
{

#ADDED HEADER FILE
open (HEAD, $headersrc);

    while (<HEAD>)
      {

  if(/<!--%%announce%%-->/)

  #print the text file
        {
        open (ANNOUNCE, $announcefile);
        @DATA2=<ANNOUNCE>;
        close (ANNOUNCE);
        foreach $item (@DATA2){
         print "$item\n";
         }

       }  #end print text file

   if(/<!--%%%jcooldate%%%-->/)
        {
require "/cgi-bin/jcooldate_cgioutput.pl";
  }

# if(/<!--%%%jssibanner%%%-->/)  # THIS
DIDN'T WORK RIGHT
#        {
#require "/cgi-bin/jssibanner_cgioutput.pl";
#  }

      print "$_";
      } # End of  while (<HEAD>)

@DATA1=<HEAD>;
close (HEAD);
foreach $item (@DATA1){
 print "$item\n";
}

} # end of sub PrintHeader

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 16 Jan 1999 16:57:25 GMT
From: richm@ucesucks.rochester.rr.com (Rich)
Subject: Re: Downloading HTML files?
Message-Id: <slrn7a1hed.n0q.richm@ll.aa2ys.ampr.org>

On Sat, 16 Jan 1999 02:17:34 -0000, Mike Watkins <mwatkins@promotion4free.com> wrote:
>Hi there,
>
>I have a list of URL's in a text file, one per line.  I was wondering, how
>could I have a script copy the source of each URL, to a text file?  I know
>there is the LWP module, and socket(), but don't really know how to use
>them.  All I need is the few lines of code to gather the source of the web
>page, into an array.
>
>Any help would be greatly appreciated,
>Mike Watkins
>


perldoc LWP::Simple

- Rich

--
Rich Mulvey                                         
http://mulvey.dyndns.com
Amateur Radio: aa2ys@wb2wxq.#wny.ny.usa


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

Date: Sat, 16 Jan 1999 08:38:31 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: filter href-links from web-page ?
Message-Id: <798q77.him.ln@magna.metronet.com>

bluepuma@mailexcite.com wrote:

: > could someone explain me how to filter href-links from a web-page ?


  You really really really want to use HTML::Parser as already
  suggested.

  Some problems with your approach that are not problems with the
  module:


: $line =~ s/.*<a href="(\S*?)(#\S*?)?">.*/$1/i

<!--
    I gotta go find out the correct URL for this link:

   <a href="somewhere.com">something</a>
-->


   You will report this instead of ignoring it.


<a
href="http://www.perl.com"
>

   You will ignore this instead of reporting it.



: okay, I got this far, but how do I omit the blank ones if it's just a
: href="#whatever" ? How can I deal with more than 1 occurence in a line ?


   More than one on a line is no problem with the module.

   It is possible for the entire HTML file to be a single line.

   Or even no lines at all...


: Is it possible to treat the file as a whole using something like //gis ?


   You don't want to.

   You want to use the HTML::Parser module.

   Really.

   You have no chance without it.

   Resistance is futile...


: Right now I have to match every single line.


   hrefs can span lines.

   You have a problem.

   The module has no such problem.



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 16 Jan 1999 15:17:53 +0000
From: Etienne Pollard <not@giving.it.out>
Subject: Re: glob error
Message-Id: <36A0ADA1.5806C334@giving.it.out>

Etienne Pollard wrote:

> I have the following code:
>
> !#/usr/bin/perl -w
>
> @another = </home/webroot/*>;
> foreach (@another) {
>     print "$_\n";
> }

Well, I've tried it with

@another = split(/ /, `echo /home/webroot/*`);

and now it works.

Btw, I'm running Perl 5.00401, not a maintenance release.

Thanks all anyway,

Etienne Pollard



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

Date: Sat, 16 Jan 1999 11:53:42 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: glob error
Message-Id: <1dlq3j7.1yrgzf3eyvkwuN@bay1-249.quincy.ziplink.net>

Jan Schipmolder <schip@lmsc.lockheed.com> wrote:

> Etienne Pollard (not@giving.it.out) wrote:
> : Tad McClellan wrote:
> : 
> snip
> : >
> : >    You cut/pasted it into this article, or you typed it in?
> 
> It must have been typed, since it's not !# but #!

No, it must have been pasted, because the reversal of #! what is causes
the compilation error!

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 16 Jan 1999 11:53:41 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: glob error
Message-Id: <1dlq3eg.1hk27xb190ur40N@bay1-249.quincy.ziplink.net>

Etienne Pollard <not@giving.it.out> wrote:

> I have the following code:
> 
> !#/usr/bin/perl -w
  ^^

> @another = </home/webroot*>;
> foreach (@another) {
>     print "$_\n";
> }
> 
> When I run it I get the following error:
> 
> Can't modify not in scalar assignment at glob.pl line 3, near
> "</home/webroot*>;"
> Execution of glob.pl aborted due to compilation errors.

Note the first line of your script.

Remember that # is the comment character.


You are executing the code

!@another = </home/webroot*>;


Thus, Perl's tells you that it cannot modify not, i.e. the logical
negation operator, in a scalar assignment.


ITYM

#!/usr/bin/perl -w



-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 16 Jan 1999 17:12:38 GMT
From: "Allan M. Due" <allan@due.net>
Subject: Re: grep question
Message-Id: <77qha6$a7g$0@206.165.165.161>

Robert Gwynne wrote in message <77q355$rcj$1@gaia.ns.utk.edu>...
:Would someone please explain how the following construction works.

Well, lets give it a try.  I sometimes get myself into trouble with these
kinds of questions.

:%FIELDS =       ('Personal
:Information'=>['Name','Address','Telephone','Fax'],
:                                'References'=>['Personal Ref 1', 'Personal
:Ref 2']
:                            );


Just for clarity, the above creates a hash of lists so each of  the two keys
('Personal Information' and 'References') has a referrence to an array as it's
value.
:
:foreach (values %FIELDS){
:            grep($ALL_FIELDS{$_}++, @$_);
:}
:
The above states: foreach of the values in %FIELDS: perform the grep.  As the
loop iterates the array refs are in $_ (these are the values in %FIELDS).  We
need to dereference these arrays thus the: @$_.   grep takes each element of
an array (here the elements in @$_) and does something to it.  grep sets each
element to a new $_ local to the grep, so outside the grep $_ is a reference
to an array (which is a value of  %FIELDS) but inside the grep $_  is an
element of the array.  Whew.

Anyway, we are creating keys in the hash %ALL_FIELDS which are the elements of
the arrays in @$_.  The values for the keys are the number of times that the
key has been encountered.  The ++ is incrementing a numeric value for each
key.  So the first time through the foreach's $_ is a reference to the array
'Name','Address','Telephone','Fax'.  We dereference it  by @$_ (we could have
said @{$_} if that is any clearer).   Then the array is fed to the grep which
sets $_ to Name, creates a key in %ALL_FIELDS with Name, and then increments
the value for that key from 0 to 1.

Lets do an example:

#!/usr/local/bin/perl -w
use strict;
my %ALL_FIELDS;
my %FIELDS =
('PersonalInformation'=>['Name','Address','Telephone','Fax'],
                 'References'=>['Personal Ref 1', 'Personal Ref 2']);

foreach (values %FIELDS){
    grep($ALL_FIELDS{$_}++, @$_);
}

foreach my $key (keys %ALL_FIELDS) {
    print "Key: $key \t was encountered : $ALL_FIELDS{$key} time\n";
}

produces:

Key: Name   was encountered : 1 time
Key: Personal Ref 1   was encountered : 1 time
Key: Personal Ref 2   was encountered : 1 time
Key: Telephone   was encountered : 1 time
Key: Address   was encountered : 1 time
Key: Fax   was encountered : 1 time

if we add an extra Name;
Information'=>['Name','Name','Address','Telephone','Fax'],
then the first line of the output would be:
Key: Name   was encountered : 2 time

We could have written the same code without the grep.

foreach $array_ref (values %FIELDS){
    foreach (@$array_ref) {
        $ALL_FIELDS{$_}++;
    }
}

I don't know if that is helpful for you or not.

Lastly I was going to say this is an example of using grep in a void context
and should be slower than using the foreach version.  However my attempt at
Benchmarking does not seem to support this.  I thought grep would need to
build up a list even though it is not used, slowing down the grep, but that
does not seem to be the case.  Of course I may well have screwed up my
Benchmark.

#!/usr/local/bin/perl -w
use strict;
my %FIELDS =
('PersonalInformation'=>['Name','Address','Telephone','Fax'],
                 'References'=>['Personal Ref 1', 'Personal Ref 2'],
                 'References2'=>['Personal Ref 1', 'Personal Ref 2'],
                 'References3'=>['Personal Ref 1', 'Personal Ref 2'],
                 'References4'=>['Personal Ref 1', 'Personal Ref 2']
                 );

sub CGIPM_grep {
    my %ALL_FIELDS;
    foreach (values %FIELDS){
        grep($ALL_FIELDS{$_}++, @$_);
    }
}

sub nogrep {
    my %ALL_FIELDS;
    foreach (values %FIELDS){
        foreach (@$_) {
            $ALL_FIELDS{$_}++;
        }
    }
}

use Benchmark;
timethese(100000, {
'CGI.PMs grep'  => \&CGIPM_grep,
'vs. No grep'  => \&nogrep
});
__END__

Benchmark: timing 100000 iterations of CGI.PMs grep, vs. No grep...
CGI.PMs grep: 38 wallclock secs (38.93 usr +  0.00 sys = 38.93 CPU)
vs. No grep: 49 wallclock secs (49.42 usr +  0.00 sys = 49.42 CPU)

HTH

AmD








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

Date: Sat, 16 Jan 1999 11:57:45 -0500
From: Stephen Bucholtz <bucholtz@erols.com>
Subject: HELP:  Writing Date/Time to Log
Message-Id: <36A0C508.538B6C9C@erols.com>

Below is a block of code I use to create the Date/Time..  When I use
printf, it writes fine to the screen, but How do I get this to write to
my log?

#*******************************
#***** Start Log File **********
#*******************************

($Second,$Minute,$Hour,$DayOfMonth,$Month,$Year,$WeekDay,$DayOfYear,$IsDST)
= localtime(time);
   $RealMonth = $Month + 1;
   open(LogFile, ">$RealMonth $DayOfMonth $Year.log")||("Log file did
not open!\n");
   print "The following Log File was created: $RealMonth $DayOfMonth
$Year.log\n";
   printf('%02d:%02d:%02d %02d/%02d/%02d', $Hour, $Minute, $Second,
$RealMonth,
   $DayOfMonth, $Year);

I tried $TimeStamp = printf(........
it gives me 99.

I normally program in VB but my boss hands me a Perl book on Monday and
says I need an app in two weeks.  So this is the first time I've ever
looked at Perl.

Stephen



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

Date: Sat, 16 Jan 1999 16:20:20 GMT
From: glo83@yahoo.com
Subject: JPL install difficulties
Message-Id: <77qe7u$kt9$1@nnrp1.dejanews.com>

hello, i would appreciate any input, if possible:  i downloaded and compiled
Perl 5.005_54, in order to try (among other things) the Java/Perl Lingo kit. 
i am running Debian GNU/Linux 2.0 (glibc2), stable kernel 2.0.34, gcc
2.7.2.3, ld 2.9.1.  i configured Perl with -Dusethreads and with libperl.so
dynamically-loaded (per the JPL instructions), but upon running
 ./install-jpl, i get the following at compile time:

[...] gcc -c -I/usr/local/java/include -I/usr/local/java/include/linux
-I/usr/local/java/include/genunix -D_REENTRANT -Dbool=char -DHAS_BOOL
-I/usr/local/include -O2  -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fpic
-I/usr/local/lib/perl5/5.00554/i586-linux-thread/CORE  JNI.c Running
Mkbootstrap for JNI () chmod 644 JNI.bs
LD_RUN_PATH="/usr/local/lib/perl5/5.00554/i586-linux-thread/CORE:/usr/local/j
pl/ lib/i586-linux-thread" gcc -o blib/arch/auto/JNI/JNI.so  -shared
-L/usr/local/lib JNI.o -R/usr/local/lib/perl5/5.00554/i586-linux-thread/CORE
-L/usr/local/lib/perl5/5.00554/i586-linux-thread/CORE
-R/usr/local/jpl/lib/i586-linux-thread -L/usr/local/jpl/lib/i586-linux-thread
-lperl -lPerlInterpreter [ **** ] gcc: unrecognized option
`-R/usr/local/lib/perl5/5.00554/i586-linux-thread/CORE' gcc: unrecognized
option `-R/usr/local/jpl/lib/i586-linux-thread' [ **** ] chmod 755
blib/arch/auto/JNI/JNI.so cp JNI.bs blib/arch/auto/JNI/JNI.bs

[...]

and then this at run-time when install-jpl tries to run the the Sample class:

Testing Sample...
+ cd Sample
+ JPLDEBUG=1
+ export JPLDEBUG
+ java Sample
/usr/local/jpl/lib/i586-linux-thread/libPerlInterpreter.so: undefined symbol:
pthread_getspecific (libSample.so)
Can't find class Sample
Couldn't run Sample

it appears both problems are thread-related, but i am not clear what the real
problem is (i'm not an expert in these matters).  does anyone have any
thoughts?  i will probably try recompiling without -Dusethreads, but i thought
i'd check with y'all first before i do, since i've been through the whole
5.005_54 install 5 or 6 times already .. 8)   thanks a lot!

glo

p.s. i'm also planning on installing kernel 2.2.0pre7 today, so maybe that'll
help?  (or maybe break things even more...)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 16 Jan 1999 17:34:42 GMT
From: spadesmcgee@my-dejanews.com
Subject: Looking for CGI modules
Message-Id: <77qiji$o8g$1@nnrp1.dejanews.com>

Hi all,

I'm writing some really simple CGI scripts, that return HTML and send emails.
No biggie.

I did all this 4-5 years ago or so, and haven't used Perl since. Since then it
seems like a lot has changed, esp as far as available packages (I used Perl 4
and have never really used modules or any of the Perl OOP stuff). I'm guessing
there are modules available for what I want to do (it's only been done like a
billion times), but where do I start?

Thanks,
Chris

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 16 Jan 1999 17:40:46 GMT
From: Chris <chrisl@hamptons.com>
Subject: Looking for free Web Server with CGI
Message-Id: <36A0CF1E.74D1E596@hamptons.com>

Hi

Are there any free Web servers for Win98 (even trial versions) that
allow me to mess around with CGI & Perl? Last time I tried this (years
ago), PWS was supposed to do it but it was broken (or I was broken, or
something)

Thanks,
Chris



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

Date: Sat, 16 Jan 1999 14:10:51 GMT
From: fernando@waycom.com.ar
Subject: question on locale
Message-Id: <77q6l7$f01$1@nnrp1.dejanews.com>

Hi,
I4m trying to develop a spanish oriented search engine in Perl and
I4m having trouble transforming accuted vowels to plain vowels.
This is in order to make the searches 4accute insensitive4.
The problem is that substitution doesn4t work.
The system:
Perl 5.004, SCO Unix OpenServer 5.0.0, and Apache 1.3.4

Does anyone know a workaround for this?
Please post the answer in the NG and e-mail it to me too.
Thank you,

Fernando
E-mail: fernando@waycom.com.ar

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 16 Jan 1999 17:48:00 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
To: fernando@waycom.com.ar
Subject: Re: question on locale
Message-Id: <oeesodb8bin.fsf@alpha.hut.fi>


fernando@waycom.com.ar writes:

> Hi,
> I4m trying to develop a spanish oriented search engine in Perl and
> I4m having trouble transforming accuted vowels to plain vowels.
> This is in order to make the searches 4accute insensitive4.
> The problem is that substitution doesn4t work.

You say "locale" in the Subject but are you really using the locale
system of Perl?  You are familiat with "man perllocale"?

You say "doesn't work".  Please give us concrete examples.
Your code, your input, your (locale) environment, your output
and errors, all exactly.  Not just "doesn't work".

> The system:
> Perl 5.004, SCO Unix OpenServer 5.0.0, and Apache 1.3.4

I don't know how well SCO supports Spanish locales, try "man locale"
and "locale -a" (if the latter doesn't work, "man perllocale" tells
of more tricks of locating the locales available) 

> Does anyone know a workaround for this?

Well, if the Perl locale system doesn't work you can always first
do things like

tr/a`i.../aae.../;

for both of your search key and a _copy_ of your data while you are
searching.

> Please post the answer in the NG and e-mail it to me too.
> Thank you,
> 
> Fernando
> E-mail: fernando@waycom.com.ar
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: 16 Jan 1999 17:19:11 GMT
From: "Allan M. Due" <allan@due.net>
Subject: Re: Removing spaces from arrays...
Message-Id: <77qhmf$av7$0@206.165.165.161>

Allan M. Due wrote in message <77oo13$gtb$0@206.165.165.159>...
:Hawkwynd wrote in message <369fb52a.14895778@news.fwi.com>...
::I have a database file that has fields seperated by spaces, and would
::like to have each field assigned to it's own variable as it is read in
::from the file.
::An example of the data file :
::6606677   Y    R  SF00 01/13/99 07:48 40-006990 INFO
::
::6600151   Y    R  SF00 01/12/99 08:27 A359      ADIC
::
::6602719   Y    R  SF00 01/12/99 11:48 B603      ADIC
::
::6603118   Y    R  SF00 01/12/99 12:15 10-509610 ADAPTEC
:: The problem here, is the spaces between lines, and between the
::variables.
::This is how I want the data to be outputted...
::6606677 | Y|R|SF00|01/13/99|07:48|40-006990|INFO
::6600151|Y|R|R|SF00|01/12/99|08:27|A359|ADIC
::For the life of me I've been unable to get the script to do this...
::
:my @ary = ('6606677   Y    R  SF00 01/13/99 07:48 40-006990 INFO',
:'                                                          ',
:'6600151   Y    R  SF00 01/12/99 08:27 A359      ADIC',
:'                                   ');
:my @foo = map {join "|",(split ' ')} grep {!/^\s*$/} @ary;

now I like
my @foo = map {!/^\s*$/ ? join "|",split : ()}@ary;
even better.

AmD

:





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

Date: Sat, 16 Jan 1999 08:23:41 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Searching a string, with a headache
Message-Id: <dd7q77.him.ln@magna.metronet.com>

dennis_marti@yahoo.com wrote:
: In article <369f3db0.2660665@news.mtt.net>,
:   gigatronman@email.com (Giga Tron) wrote:
: >
: > I have to read a file that can be any size, and contain unstructured


   Looks structured to me...


: > data. The file could be like this.
: >
: > stuff|morestuff*morestuff*morestuff*morestuff|evenmo ...

: Let Perl find your record separators.
: Take a look at the $/ special variable.


   Please give a small snippet that shows what you're talking about.

   I see no way of bending $/ to this purpose (since there is no
   constant string that marks only the end of a record)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 16 Jan 1999 17:50:42 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Searching a string, with a headache
Message-Id: <36A0D33C.E931ECFD@home.com>

Tad McClellan wrote:
> 
> dennis_marti@yahoo.com wrote:
> : In article <369f3db0.2660665@news.mtt.net>,
> :   gigatronman@email.com (Giga Tron) wrote:
 
> : > data. The file could be like this.
> : >
> : > stuff|morestuff*morestuff*morestuff*morestuff|evenmo ...
> 
> : Let Perl find your record separators.
> : Take a look at the $/ special variable.
> 
>    Please give a small snippet that shows what you're talking about.
> 
>    I see no way of bending $/ to this purpose (since there is no
>    constant string that marks only the end of a record)

I think '|' is a constant string.  ;-)  

Giga Tron says it marks the _beginning_ of a record but I don't see why
it can't be used as the record separator.

$/ = '|';
my $header = <>;# if the stuff before the first '|' isn't a record
while(<>) {
    chomp;
    my @fields = split /\*/;
}

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: 16 Jan 1999 14:55:24 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Stopping <ctrl>-c during perl Scripts (win32)
Message-Id: <19990116095524.12143.00001201@ng140.aol.com>

Hi Clay and Gareth:

>>I have a script I've written that I need all users to run.  I don't want
>>them stopping it
>>with a control - c or a control break.  Is there any way to do this?
>
>>I will be running the scripts on evil 95 and NT stations.
>
># perldoc -q SIGNAL
>=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod
>
>=head2 How do I trap control characters/signals?
>
>You don't actually "trap" a control character.  Instead, that character
>generates a signal which is sent to your terminal's currently
>foregrounded process group, which you then trap in your process.
>Signals are documented in L<perlipc/"Signals"> and chapter 6 of the Camel.

Unfortunately, many of the signals do not work on NT - and even
fewer on Win95. I scanned the Win32-specific FAQs, but didn't
find the details. There was an extended discussion of this on the
Perl-Win32-Users list  couple of months ago - and someone posted
a detailed description. You might want to check the list archives on
the ActiveState site.

-bill

Making computers work in Manufacturing for over 25 years (inquiries welcome)


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

Date: 16 Jan 1999 09:19:54 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: The number of seconds since 1/1/1970 ?
Message-Id: <77qe7a$cn6@flatland.dimensional.com>

b_macbob@NOSPAM.hotmail.com (Bob MacBob) writes:

> I have perl5 on apache/unix - great.
>
> How can I use a SSI to insert the number of seconds since 1/1/1970
> into a document without calling a script to output the value?

Check your HTTP server documentation -- this has nothing to
do with Perl.  It would be better to ask in one of the
comp.infosystems.www.servers.* newsgroups.

> The following script works when called by an '#include virtual=':
>
> #!/usr/lib/bin/perl5
> $seconds = time;
> print "Content-type: text/html\n\n";
> print "$seconds";
>
> But I'm hoping their's a tidier way using environment variables and
> timefmt or something like that.

There is, at least if you're using Apache.  Seek, and ye shall find.

-- 
Michael Fuhr
http://www.fuhr.net/~mfuhr/


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

Date: Sat, 16 Jan 1999 08:16:50 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <i07q77.him.ln@magna.metronet.com>

Rick Delaney (rick.delaney@home.com) wrote:

: This will work if the processing was going to involve chomping the lines
: anyway.

:     while ( $string =~ /^(.*)$/gm ) {
                               ^
                               ^ don't really need that.


: I'm having trouble coming up with a clean way to retain the newlines,
: though.


   while ( $string =~ /(.*\n?)/g ) {

   :-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 16 Jan 1999 11:53:39 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <1dlq2yx.2npxandvt472N@bay1-249.quincy.ziplink.net>

Rick Delaney <rick.delaney@home.com> wrote:

> This will work if the processing was going to involve chomping the lines
> anyway.
> 
>     while ( $string =~ /^(.*)$/gm ) {
> 
> I'm having trouble coming up with a clean way to retain the newlines,
> though.

    while ( $string =~ /^(.*(?:$)\n?)/gm ) {

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 16 Jan 1999 17:35:34 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <36A0CFAF.16FCCCC1@home.com>

[posted & mailed]

Tad McClellan wrote:
> 
> Rick Delaney (rick.delaney@home.com) wrote:
> 
> :     while ( $string =~ /^(.*)$/gm ) {
>                                ^
>                                ^ don't really need that.
> 

Yes. I originally had

    while ( $string =~ /(.*)$/gm ) {

but that doesn't work right because the '.*' matches an extra time at
each record.  So I added the '^' without removing the '$'.

> : I'm having trouble coming up with a clean way to retain the 
> : newlines, though.
> 
>    while ( $string =~ /(.*\n?)/g ) {

I tried this too which has the same problem of the null pattern matching
twice (at the last record in this case).

#!/usr/bin/perl -w

$string = "Line 1\nLine 2\nLine 3";

while ( $string =~ /(.*\n?)/g ) {
    print "$1SEPARATOR\n";
}

gives:

Line 1
SEPARATOR
Line 2
SEPARATOR
Line 3SEPARATOR
SEPARATOR

I can't think of any practical use for this since it shouldn't matter if
you put newlines back onto all records, but now I'm curious.  It seems
like a simple little problem but I can't think of a simple little regex
to handle it.

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4669
**************************************

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