[17254] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4676 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 20 14:05:44 2000

Date: Fri, 20 Oct 2000 11:05:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972065119-v9-i4676@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 20 Oct 2000     Volume: 9 Number: 4676

Today's topics:
    Re: Boolean query to Perl regexp match conversion (Eric Bohlman)
    Re: Creating perl modules (Michael Houghton)
        Device::SerialPort no dial even parity <phil_xxx@my-deja.com>
        Encrypted file transfer slavinger@my-deja.com
        EOF character in middle of file? p_erion@yahoo.com
        FedEx and CanadaPost Modules? bluearchtop@my-deja.com
    Re: Filehandle redirection (Eric Bohlman)
    Re: finding mode and median of an array of numbers (Andrew J. Perrin)
    Re: Finding two words in any order in string? (Eric Bohlman)
    Re: Finding two words in any order in string? <godzilla@stomp.stomp.tokyo>
    Re: God, this is like hard work... (Eric Bohlman)
    Re: God, this is like hard work... <anders@wall.alweb.dk>
    Re: Going from Linux RPM Perl 5.00503 to compiled 5.6.0 <anders@wall.alweb.dk>
    Re: Help ! DBI error <befe@ir.phys.chem.ethz.ch>
        Help with Split.... <mezmoria@hotmail.com>
    Re: Help with Split.... <anders@wall.alweb.dk>
    Re: Help with Split.... nobull@mail.com
    Re: Help with Split.... <mezmoria@hotmail.com>
    Re: Help with Split.... <mjcarman@home.com>
    Re: Help with Split.... <jeff@vpservices.com>
    Re: Help with Split.... nobull@mail.com
        Help!! converting strings to packed signed hexadecimal yevziig@my-deja.com
    Re: Help!! converting strings to packed signed hexadeci <anders@wall.alweb.dk>
    Re: how do i find file size? <me@privacy.net>
    Re: How to find out the number of lines in a flat file. <jgoldst@my-deja.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 20 Oct 2000 15:51:52 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Boolean query to Perl regexp match conversion
Message-Id: <8sppmo$1lpp$4@news.enteract.com>

Randy Kobes <randy@theoryx5.uwinnipeg.ca> wrote:
>     Take a look at the Text::Query::Advanced module, which matches
> some text against a boolean expression, similar to an AltaVista
> advanced query. See, for example,
> http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search?doc=Text::Query::Advanced
> for documentation.

Text::Query::Advanced and Text::Query::Simple have been superseded by
Text::Query (which actually includes wrapper submodules named after the
old ones).



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

Date: 20 Oct 2000 13:00:32 -0400
From: herveus@Radix.Net (Michael Houghton)
Subject: Re: Creating perl modules
Message-Id: <8sptng$h72$1@saltmine.radix.net>

Howdy!

In article <0QsH5.851$SF5.17787@ozemail.com.au>,
Troy Rasiah <troyr@vicnet.net.au> wrote:
>Hi there,
>         I was wondering if anyone could give me a pointer in the right
>direction or a sample procedure as on to how to make my own modules. I have
>read perldoc -q "how to create modules" and have tried a sample script but
>am missing something or other.
>
perldoc ExtUtils::MakeMaker

provides some useful tidbits...

yours,
Michael
-- 
Michael and MJ Houghton   | Herveus d'Ormonde and Megan O'Donnelly
herveus@radix.net         | White Wolf and the Phoenix
Bowie, MD, USA            | Tablet and Inkle bands, and other stuff
                          | http://www.radix.net/~herveus/


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

Date: Fri, 20 Oct 2000 16:00:01 GMT
From: Phil xxx <phil_xxx@my-deja.com>
Subject: Device::SerialPort no dial even parity
Message-Id: <8spq5u$aac$1@nnrp1.deja.com>

I have been learning to use the Device::SerialPort module.
I can get my program to dial if I use :

$modem_obj->parity("none").

When I use :

$modem_obj->parity("even")     || die "fail setting parity";
$modem_obj->parity_enable('T');

It wont dial.

I am using i86 Solaris 8 and perl 5.6.0.

Any ideas?  Maybe its a port setting?





Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 20 Oct 2000 15:43:05 GMT
From: slavinger@my-deja.com
Subject: Encrypted file transfer
Message-Id: <8spp66$9b9$1@nnrp1.deja.com>

Hello,

We're looking for a method of setting up encrypted link for transferring
files in Perl.  We need to do the following:  a Unix client makes a
request to a Win2k server (KDC) to generate a Kerberos keytab file for
the client.  Then the Win2k server pushes this file to the client.  We
would like to set up an encrypted channel for transferring this file.  I
looked around a bit and found some LWP modules that might work (like
LWP::SecureSocket).  The interface has to be supported on both sides:
Win32 on one and Solaris/HP-UX/IRIX on the other.  Does anyone have any
particular module(s) recommendations?

Thanks.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 20 Oct 2000 16:46:44 GMT
From: p_erion@yahoo.com
Subject: EOF character in middle of file?
Message-Id: <8spsth$d01$1@nnrp1.deja.com>

I'm having a bit of a problem reading the lines of a text file.
Somehow there are some garbage characters in the file and one
of them [\x1A or ^Z] seems to be interpreted as the EOF character
[on a Windows machine].  At least, once that character is reached,
reading stops, but I know more text follows.  I've tried to simplify
things as much as possible ... so the perl script is:

    $lines = 0;
    while (<>) {
    	print ("$_");
        $lines++;
    }
    print "\nCount: $lines\n";

The contents of the test file is three lines long [with the
"bad" character on the second line:

A
B
C

The hex values of that file being:

	41 0D 0A 42 1A 0D 0A 43 0D 0A

Is there someway that I can get around this eof character?

Thanks,

:Paul

Disclaimer: I'm new to Perl so I may have missed something or be doing
something incredibly stupid ...


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 20 Oct 2000 15:58:04 GMT
From: bluearchtop@my-deja.com
Subject: FedEx and CanadaPost Modules?
Message-Id: <8spq27$a8u$1@nnrp1.deja.com>

I know there is a UPS shipping calculation module, but does anyone have
one for FedEx or Canada Post?  Or some scripts?
Thanks in advance.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 20 Oct 2000 15:11:14 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Filehandle redirection
Message-Id: <8spnai$1lpp$1@news.enteract.com>

Ben Kennedy <bkennedy@hmsonline.com> wrote:

> One way would be to create a tie package that captures print() statements,
> then tie STDOUT to it (or another handle you have select()'ed).  See perldoc
> perltie for more information.

Already been done; IO::Scalar in the IO::Stringy bundle will do just that.



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

Date: 20 Oct 2000 10:42:00 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: finding mode and median of an array of numbers
Message-Id: <ur95bfubr.fsf@demog.berkeley.edu>

Bart Lateur <bart.lateur@skynet.be> writes:

> Godzilla! wrote:
> 
> >Alright, I'll level with you boys, this one time.
> >I did not 'get' those definitions anywhere. I made
> >them up.
> 
> Gee. And all other docs I can find seem to (roughly) agree with your
> definition.
> 
> Here's one example:
> 
> http://library.thinkquest.org/17038/admission/math/meanmodemedian-question.html
> 
>   the mean is the average of a set of numbers; to calculate it, you take
>   the sum of each of the terms in the set and then you divide that sum
>   by the total number of items you have in your set. 
> 
>   the mode is a number in a set that occurs most often. 

Some definitions, though, say a multimodal distribution (e.g., where
there are more than one mode) have undefined modes, while others say
(with purlmoron) the mode is a set or list.

ap

-- 
----------------------------------------------------------------------
Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology  
Chapel Hill, North Carolina, USA - http://demog.berkeley.edu/~aperrin
        aperrin@socrates.berkeley.edu - aperrin@igc.apc.org


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

Date: 20 Oct 2000 15:40:50 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Finding two words in any order in string?
Message-Id: <8spp22$1lpp$2@news.enteract.com>

Stephane Barizien <sba@ocegr.fr> wrote:
> What I forgot to mention is that I have my patterns in a file, so I'd
> like to avoid duplicating all cases in that file, like:

> foo.*bar
> bar.*foo


> The code checks if one or more of the patterns in the file match (thus
> ORing the conditions -- that's why I need to have foo AND bar in the
> same pattern)...

> Can this lead you all to solutions closer to "my definition of the
> problem?"

You might want to look into Text::Query.



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

Date: Fri, 20 Oct 2000 09:41:20 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Finding two words in any order in string?
Message-Id: <39F075B0.3EDA84A6@stomp.stomp.tokyo>

Stephane Barizien wrote:

> I have a big multiline (embedded \n's) string in $str.
 
> I want to check if $str contains two (or more, but that's next) words,
> in any order...
 
> What's better than:
 
> foo.*bar|bar.*foo



$counter = 1;
while (<DATA>)
 {
  $_ = " $_ ";
  $_ =~ s/-/ /g;
  $_ =~ s/\W+/ /g;
  if (index ($_, " this ") > -1)
   {
    if (index ($_, " that ") > -1)
     { print "This and That found at line $counter\n"; }
   }
  $counter++;
 }
print "\n\n     Search Finished";



You need to compensate for compound words which
may contain your root word or words of interest.
Words which are hyphenated present a challenge
as well. Dealing with data which contains html
format tags, underscores and data which contains
accented letters and perhaps spaces and other
characters as a normal part of a whole word, 
also presents some challenges.

anybody
anyhow
anymore

everyday
everyone
everything

à l'anglaise
cliché
número uno

apico-alveolar
Chinese-American
zip-lock


These two lines present problems, in compensating
for problems:

  $_ =~ s/-/ /g;
  $_ =~ s/\W+/ /g;

Removing a hyphen is a personal choice depending
on your 'definition' of a word. Replacing non-word
characters with a space, also wipes accented letters
along with hyphens, apostrophes and the such, which
can be a part of a normal word.

Use of a word boundry for a regex would help quite
a bit but would miss many odd cases for words.


You really need to establish some spelling rules
for your program if it is to be effective and
produce correct results a majority of the time.


Godzilla!


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

Date: 20 Oct 2000 15:46:28 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: God, this is like hard work...
Message-Id: <8sppck$1lpp$3@news.enteract.com>

The Moriman <themoriman@ntlworld.com> wrote:
> How do I search the array to find 'good old Bob'?
> I tried

>     for ($i=0; $i<=$#myarray; $i++){
>         if ($myarray[$i] eq 'good old Bob') {
>             print <<END;
>                 $myarray[$i]<br>
> END
>         }
>         else {
>             print <<END;
>                 Not this one<br>
> END
>         }
>     }

> (the html header and footer are set up properly) but all I get is a list of
> 'Not this one'.
> I've tried putting 'good old Bob' in "" instead of '', I've tried == instead
> of eq (but didn't expect that to work anyway).

> Can anybody put me out of my misery?

In a later post you mention that the contents of $myarray were read from a
text file.  Is it possible that the entries have trailing newlines?


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

Date: Fri, 20 Oct 2000 17:49:16 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: God, this is like hard work...
Message-Id: <JQZH5.8262$Tq1.303544@news010.worldonline.dk>

The Moriman wrote:

> Why did they make Perl so difficult to learn?

They didn't;-))

Get "Learning Perl" by Randal Schwartz (o'reilly)

> I've read the FAQ's , the Perl documentation (that seems to be excellent,
> but assumptions are made about what you already know, which in my case
> appears to be a big fat nothing)
> I can write full blown win32 apps in ASM but can't get a grip on
> Javascript at all :-(
> 
> Any way, enough griping..
> 
> Very basic question, I have an array such that I 'know' that $myarray[2]
> has the value of 'good old Bob' (without quotes),
> 
> How do I search the array to find 'good old Bob'?
> I tried
> 
>     for ($i=0; $i<=$#myarray; $i++){
>         if ($myarray[$i] eq 'good old Bob') {
>             print <<END;
>                 $myarray[$i]<br>
> END
>         }
>         else {
>             print <<END;
>                 Not this one<br>
> END
>         }
>     }
> 

for (@myarray) {
   # each element is assigned to $_ and block evaluated, 
   # use "," operator to print and go to next iteration if
   # the regexp matches
   print "$_<br>", next if (/^good old Bob$/);
   # only gets here if regex didn't match
   print "Not this one<br>";
}

or


# c style condition ? trustatement : falsestatement.
# having the "for" (or if, unless etc) _behind_ the action is one of the
# fun things with perl 
print (/^good old Bob$/ ? "$_<br>" : "Not this one<br>") for (@myarray);

or


# more like c/java style
foreach $thing (@myarray) {
    if ($thing eq 'good old Bob') {
        print $thing, '<br>';
    } else {
        print 'Not this one<br>';
    }
}


-anders

-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


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

Date: Fri, 20 Oct 2000 17:31:53 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Going from Linux RPM Perl 5.00503 to compiled 5.6.0 - libraries are not in @INC now!  Help!
Message-Id: <rAZH5.8242$Tq1.302328@news010.worldonline.dk>

Scott Chapman wrote:
> >
> >Did you uninstall the rpm's? Most rpm packages should have scripts to
> >clean up your system when you uninstalls them.
> >
> If I uninstalled the old version, It would not remove my old
> /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux (and
> other) directories would it?  They have other files in them from pod's
> I've fetched off CPAN that the RPM system doesn't know about.
> 
> I've often wondered if I should reinstall all my pods from cpan, etc.
> when I upgrade Perl as well so that they get put in the correct tree
> structure.  (It would be nice if they were installed in a generic tree
> structure, rather than perl-version specific, if they can be used
> across perl versions).
> 
> How do you Perl guru's deal with this?

Well, I haven't really had any problems of that kind.
I've upgraded my rpm perl without problems, useing rpm -U through kpackage 
on my mandrake system.

I allways download my modules using ftp, and saves them to disk so that I 
can reinstall them in case of trouble.

One option is your perl binary, and where it points to: on my system,
/usr/bin/perl      is a symlink to
/usr/bin/perl5     is a symlink to
/usr/bin/perl5.6.0

Make sure that this is OK

Tjeck if your environment has a PERLLIB or PERL5LIB variable that points 
perl to the old dirs, if so correct it. I don't have either, which means 
that perl will look for the dirs corresponding to its version. 

-anders

-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


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

Date: Fri, 20 Oct 2000 18:22:56 +0200
From: befe <befe@ir.phys.chem.ethz.ch>
Subject: Re: Help ! DBI error
Message-Id: <39F07160.F10E7FEF@ir.phys.chem.ethz.ch>

NDQ wrote:
> 
> Hi,
> I'm newbie with DBI. My test is :
> -------------------------------------------
> #!/usr/bin/perl
> 
> use DBI;
> $driver = "mysql";
> $database = 'toto';
> $hostname = 'localhost';
> $port = '';
> $dsn = "DBI:$driver:database=$database;host=$hostname";
> 
> $user= 'foo';
> $password = 'bla';
> 
> $dbh = DBI->connect($dsn, $user, $password);
> 
> $sth = $dbh->prepare("SELECT name,email FROM vietlug");
> $sth->execute;
> $numRows = $sth->rows;
> print "num of row = $numRows\n";
> $numFields = $sth->{'NUM_OF_FIELDS'};
> while(my @row = $sth->fetchow_array()){
>     for (my $i = 0;  $i < $numFields;  $i++) {
>         print $row[$i],($i ? "," : "");
>     }
>     print "\n";
> }
> $sth->finish;
> $dbh->disconnect();
> 
> I got result always with error :
> 
> num of row = 116
> Can't locate object method "fetchow_array" via package "DBI::st" at
> ./test-DBI.pl line 22
> 
> I'm under RH6.1/DBI-1.14/MySQL-3.22.32/Perl-5.00503.
> 
> Thanks in advance,
> --
> NGUYEN-DAI Quy

Hi,

Try it with "fetchrow_array" (not "fetchow_array") ;-)

Greetings


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

Date: Fri, 20 Oct 2000 10:26:51 -0500
From: "Mezmoria" <mezmoria@hotmail.com>
Subject: Help with Split....
Message-Id: <26DE04D162000843.66E7BAAE4D9CF447.64BB1EAAD984A22D@lp.airnews.net>

Ok, I admit it I suck as a programmer. I guess thats why I dont program full
time :). Anyway I need help from you experts out there.

I am trying to create an array from a line of text that has no formatting
and I cannot figure out how to seperate the fields.


Here is the original text.. (including spaces)
1111111111        00000011111110000001111111TEST
COMPANY11111111111636459802000101700

This is how I want it to look...
1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,63645980,2000
101700


Thank You Very Much..

Mez


PS... I am posting this to three perl groups cuz I am not sure which one is
correct for this type of question.......







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

Date: Fri, 20 Oct 2000 18:16:25 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Help with Split....
Message-Id: <ae_H5.8292$Tq1.304692@news010.worldonline.dk>

Mezmoria wrote:

> Ok, I admit it I suck as a programmer. I guess thats why I dont program
> full time :). Anyway I need help from you experts out there.
> 
> I am trying to create an array from a line of text that has no formatting
> and I cannot figure out how to seperate the fields.
> 
> 
> Here is the original text.. (including spaces)
> 1111111111        00000011111110000001111111TEST
> COMPANY11111111111636459802000101700
> 
> This is how I want it to look...
> 
1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,63645980,2000
> 
1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,63645980,2000
> 101700
> 
> 
> Thank You Very Much..
> 
> Mez
> 
> 
> PS... I am posting this to three perl groups cuz I am not sure which one
> is correct for this type of question.......
> 
This is a good place for such questions 

Did you read the documentation for split? perldoc -f split in a term 
(unix/linux)
 or "dos window" for the unfortunate.

Assuming that there is whitespace between each element:

#!/usr/bin/perl -w
use strict;          # -w flag and strict pragma is the
                     # start of becomming a better perl programmer;-)

my $string = "1111111111        0000001111111 0000001111111         
TESTCOMPANY       11111111111     63645980      2000101700";

print "Data: $string\n";

# create an array of the elements, split on more or less whitespace
my @list = split /\s+/, $string;

# just create a formatted string
(my $formatted_string = $string) =~ s/\s+/,/g;

# just change original string
$string =~ s/\s+/,/g;

# print all the results
print "Results:\n\@list: @list\n \$formatted_string: $formatted_string\n 
\$string: $string\n";

__END__


If you have whitespace between some elements but not all, oyu need to read 
and become a better programmer;-))

-anders
-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


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

Date: 20 Oct 2000 17:17:00 +0100
From: nobull@mail.com
Subject: Re: Help with Split....
Message-Id: <u98zrjtrlv.fsf@wcl-l.bham.ac.uk>

"Mezmoria" <mezmoria@hotmail.com> writes:

> I am trying to create an array from a line of text that has no formatting
> and I cannot figure out how to seperate the fields.

You have just stated an impossible problem.  If your input really conforms to
no format you can't parse it.  End of story.

> Ok, I admit it I suck as a programmer. I guess thats why I dont program full
> time :). Anyway I need help from you experts out there.

That's irrelevant.  You can't define the problem then even being
infinitely good programmer cannot help you.

> Here is the original text.. (including spaces)
> 1111111111        00000011111110000001111111TEST
> COMPANY11111111111636459802000101700

> This is how I want it to look...
> 1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,63645980,2000
> 101700

So can you describe how you (a human) got from the one to the other?
Did you simply split the string at fixed offsets, remove the spaces
then join the bits together with commas?  Or did you do something
else?

Records with fixed length fields are best parsed with unpack().

> PS... I am posting this to three perl groups cuz I am not sure which one is
> correct for this type of question.......

Spamming is never right.  If you think your post may be relevant in
multiple newsgroups then crosspost.  Do not, I repeat "do not", Spam.
Not ever.

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


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

Date: Fri, 20 Oct 2000 11:49:20 -0500
From: "Mezmoria" <mezmoria@hotmail.com>
Subject: Re: Help with Split....
Message-Id: <D8014CED09F7B7A9.750CE8786C833898.E97132D6266264C6@lp.airnews.net>

Hey thanks for the help. THe problem I am having though is that the text
comes from another program and some of the fields are not seperated by
anything. For example...

Original Text

1111111111        00000011111110000001111111TESTCOMPANY11111111111
636459802000101700

How I want it to look.

1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,
63645980,2000101700

There is no space between the middle fields. I was wondering if there was a
way to tell perl to split based on the number of characters.





Thanks Again

Mez


"Anders Lund" <anders@wall.alweb.dk> wrote in message
news:ae_H5.8292$Tq1.304692@news010.worldonline.dk...
> Mezmoria wrote:
>
> > Ok, I admit it I suck as a programmer. I guess thats why I dont program
> > full time :). Anyway I need help from you experts out there.
> >
> > I am trying to create an array from a line of text that has no
formatting
> > and I cannot figure out how to seperate the fields.
> >
> >
> > Here is the original text.. (including spaces)
> > 1111111111        00000011111110000001111111TEST
> > COMPANY11111111111636459802000101700
> >
> > This is how I want it to look...
> >
>
1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,63645980,2000
> >
>
1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,63645980,2000
> > 101700
> >
> >
> > Thank You Very Much..
> >
> > Mez
> >
> >
> > PS... I am posting this to three perl groups cuz I am not sure which one
> > is correct for this type of question.......
> >
> This is a good place for such questions
>
> Did you read the documentation for split? perldoc -f split in a term
> (unix/linux)
>  or "dos window" for the unfortunate.
>
> Assuming that there is whitespace between each element:
>
> #!/usr/bin/perl -w
> use strict;          # -w flag and strict pragma is the
>                      # start of becomming a better perl programmer;-)
>
> my $string = "1111111111        0000001111111 0000001111111
> TESTCOMPANY       11111111111     63645980      2000101700";
>
> print "Data: $string\n";
>
> # create an array of the elements, split on more or less whitespace
> my @list = split /\s+/, $string;
>
> # just create a formatted string
> (my $formatted_string = $string) =~ s/\s+/,/g;
>
> # just change original string
> $string =~ s/\s+/,/g;
>
> # print all the results
> print "Results:\n\@list: @list\n \$formatted_string: $formatted_string\n
> \$string: $string\n";
>
> __END__
>
>
> If you have whitespace between some elements but not all, oyu need to read
> and become a better programmer;-))
>
> -anders
> --
> [ the word wall - and the trailing dot - in my email address
> is my _fire_wall - protecting me from the criminals abusing usenet]




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

Date: Fri, 20 Oct 2000 11:35:33 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Help with Split....
Message-Id: <39F07455.AD2105FC@home.com>

Mezmoria wrote:
> 
> I am trying to create an array from a line of text that has no
> formatting and I cannot figure out how to seperate the fields.

If your text truly has *no* formatting, then there's no way to know what
to do, and you're SOL. There must be some rule that defines the layout.
 
> Here is the original text.. (including spaces)
> 1111111111        00000011111110000001111111TEST
> COMPANY11111111111636459802000101700

Does it include the newline as well or did my newsfeed just wrap it?

At any rate, what *do* you know about the line? It's not delimited, so
split() isnt useful here. Are the fields you want of fixed sizes? If so,
you simply need to use substr() to pull out pieces.

e.g.
$foo = substr($line, 18, 13);

would pull out the first '0000001111111' sequence.

> PS... I am posting this to three perl groups cuz I am not sure 
> which one is correct for this type of question.......

c.l.p.misc is a good place for this question. However, if you do decide
to post a message to multiple groups, please cross-post it instead of
posting to each group seperately.

-mjc


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

Date: Fri, 20 Oct 2000 10:09:25 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Help with Split....
Message-Id: <39F07C45.82B52341@vpservices.com>

Mezmoria wrote:
> 
> Hey thanks for the help. THe problem I am having though is that the text
> comes from another program and some of the fields are not seperated by
> anything. For example...
> 
> Original Text
> 
> 1111111111        00000011111110000001111111TESTCOMPANY11111111111
> 636459802000101700
> 
> How I want it to look.
> 
> 1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,
> 63645980,2000101700
> 
> There is no space between the middle fields. I was wondering if there was a
> way to tell perl to split based on the number of characters.

Well, you didn't mention before that you know the number of characters
in each field.  If you know the number of characters, you need to use
unpack(), not split().

my @cols = unpack('A18 A13 A13 A11 A11 A10',$str);

-- 
Jeff


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

Date: 20 Oct 2000 18:02:57 +0100
From: nobull@mail.com
Subject: Re: Help with Split....
Message-Id: <u91yxbtpha.fsf@wcl-l.bham.ac.uk>

"Mezmoria" <mezmoria@hotmail.com> writes upside down:

> Hey thanks for the help. THe problem I am having though is that the text
> comes from another program and some of the fields are not seperated by
> anything. For example...
> 
> Original Text
> 
> 1111111111        00000011111110000001111111TESTCOMPANY11111111111
> 636459802000101700
> 
> How I want it to look.
> 
> 1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,
> 63645980,2000101700
> 
> There is no space between the middle fields. I was wondering if there was a
> way to tell perl to split based on the number of characters.

Yes sure, you can use unpack(), substr() or even m// (and sometimes
combinations thereof) depending in the exact details of what you want
to do.  If you come back and say "how?" without reading the manpages
for the above functions I swear I'll screem.

Mezmoria then qoutes the _whole_ of Anders' message to which he is replying.
This is extreemly rude.  If you want people here to treat you with any
respect at all then do not behave in such an overtly offensive manner.

If on the other hand your aim is to attract complaints (i.e. you are a
Troll) then please go Troll elsewhere.

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


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

Date: Fri, 20 Oct 2000 15:15:12 GMT
From: yevziig@my-deja.com
Subject: Help!! converting strings to packed signed hexadecimal
Message-Id: <8spnhp$80s$1@nnrp1.deja.com>

I need to convert ASCII date and time strings to corresponding zero
filled, packed signed hexadecimal values, for COBOL program. This
packed value should have right most nibble as a sign.

Date string is 5 bytes long, and is formatted like this: MM/DD
Packed hexadecimal value is also 5 bytes long, and is formatted like
this: 0YYYYMMDD. Precision should be 9.0

Time string is 4 bytes long, and is formatted like this: HH/MM
Packed hexadecimal value is also 4 bytes long, and is formatted like
this: 0HHMMSS. Precision should be 7.0

Any help would be highly appreciated.

Thank you very much.





Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 20 Oct 2000 18:17:24 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Help!! converting strings to packed signed hexadecimal
Message-Id: <5f_H5.8294$Tq1.304399@news010.worldonline.dk>

yevziig@my-deja.com wrote:

> I need to convert ASCII date and time strings to corresponding zero
> filled, packed signed hexadecimal values, for COBOL program. This
> packed value should have right most nibble as a sign.
> 
> Date string is 5 bytes long, and is formatted like this: MM/DD
> Packed hexadecimal value is also 5 bytes long, and is formatted like
> this: 0YYYYMMDD. Precision should be 9.0
> 
> Time string is 4 bytes long, and is formatted like this: HH/MM
> Packed hexadecimal value is also 4 bytes long, and is formatted like
> this: 0HHMMSS. Precision should be 7.0
> 
> Any help would be highly appreciated.

It's in your docs:

$perldoc -f pack

-anders
-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


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

Date: Fri, 20 Oct 2000 16:27:52 GMT
From: "EM" <me@privacy.net>
Subject: Re: how do i find file size?
Message-Id: <co_H5.7169$44.21408@news.iol.ie>


"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8uvabb.fji.mgjv@martien.heliotrope.home...
> [please, in the future, put your reply _after_ the suitably trimmed
> text you reply to. It makes followups easier to read, and is in
> accordance with the generally accepted style on this group, and Usenet
> as a whole.]

OK

> Not that I know of with LWP::Simple. In any case, you won't be able to
> show anything in the browser, because this doesn't run in the browser,
> unless you mean that your program is the browser?
>
> If you use LWP::UserAgent directly, you can define a callback sub, as
> well as a chunk size. If you do so, LWP will call that sub for each
> chunk downloaded, and you can decide what to do at that moment. You will
> have to take care of everything yourself: Saving of data, updating
> counters, etc.

I dont really understand but i figured out how to show the status

> How to display this information in a browser, so that it updates live
> I'll leave up to you. You'll have to go to comp.infosystems.www.*
> somewhere to find out how to do that sort of stuff over HTTP.

Thanks for the tip

> A good starting point could be:

<SNIPPED SCRIPT CODE>

Thats great but that script is a command line script
I aleady have a command line script for this
Basically i want a script that i enter the urls to download and it transfers
the file
I have done all this but i would like to know
How do i set what i want the http referer to be?
How do i set the useragent (not that important)?

Now i figured out how to do this with LWP but it loads the file into memory
& then writes to a file
this is not good for large files because i would be using up all the servers
memory, i want to be able to transfer large files

I got most of this from cpan.com
it was a command line script which printed the downloaded file to the screen
but i modified it so its not a command line and it saves the download to a
file
If you could show me how to modify it so that the download is not stored in
memory like getstore

#!/usr/bin/perl

$url = "http://www.server.com/file.zip";
$saveto = "./test/file.zip";
$referer = "http://www.server.com/links.html";

  # Create a user agent object
  use LWP::UserAgent;
  $ua = new LWP::UserAgent;
  $ua->agent("Mozilla/4.0 \(compatible; MSIE 5.5; Windows 98; Win 9x 4.90;
DigExt\)");


  # Create a request
  my $req = new HTTP::Request GET => $url;
  $req->referer("$referer");
  $req->content('match=www&errors=0');


  # Pass request to the user agent and get a response back
  my $res = $ua->request($req);


  # Check the outcome of the response
  if ($res->is_success) {
  open (FILE,">$saveto");
  print FILE $res->content;
  close (FILE);

print "Content-type: text/html\n\n";
print qq~DONE~;
exit;

  } else {
      print "Content-type: text/html\n\n";
      print qq~Bad luck this time~;
      exit;
  }




>
> Isn't it good that the LWP modules exist? It's now possible to write
> little tools like these in less time than it takes to get a coffee.

yep :)
but i noticed if i try to transfer 2 files at the same time the 1st one
stops :(
Is there a way to resume a download?
Also is there a way to detect if transfer is interrupted by someone else
using lwp and try again until success?

> Oh, note that some of the above might not work on all terminals. It
> works for me, but it may not work for you.

Its all worked so far :)

Hope i have not asked too much
Thanks again




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

Date: Fri, 20 Oct 2000 16:13:05 GMT
From: JL Goldstein <jgoldst@my-deja.com>
Subject: Re: How to find out the number of lines in a flat file.....
Message-Id: <8spqu8$aut$1@nnrp1.deja.com>

In article <c0muus86hf77rs5ott92mr9prg2p0a65gi@4ax.com>,
  Slim <ShadeyGradey@hotpop.com> wrote:

> I'm trying to make a image gallery script and I'm using many flat file
> databases..... they all may have more or less lines and I want to know
> how to get the number of lines there are.....

	$numlines = `wc -l $filename`;

works great for me....


----
Any sufficiently advanced magic is indistinguishable from Perl.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4676
**************************************


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