[19373] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1568 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 20 09:05:59 2001

Date: Mon, 20 Aug 2001 06:05:10 -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: <998312710-v10-i1568@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 20 Aug 2001     Volume: 10 Number: 1568

Today's topics:
        -w pragma (Nkhouri)
    Re: -w pragma (Helgi Briem)
    Re: Copy file in Perl <Graham.T.Wood@oracle.com>
    Re: Copy file in Perl <ilya@martynov.org>
        embedding perl in java <BAHA0011@prodigy.net>
        Error involves unreferenced scalar, unblessed reference (Greg)
    Re: Error involves unreferenced scalar, unblessed refer <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Error involves unreferenced scalar, unblessed refer <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Hash of Complex Records <mark.riehl@agilecommunications.com>
    Re: Hash of Complex Records (Eric Bohlman)
        Perl Embed repeated allocation with diagnostics <klimek@fmi.uni-passau.de>
    Re: perldoc is like Greek to a beginner?? (Abigail)
        Please advice... <simon.forsell@lumumba.com>
    Re: redirecting stdin and stdout <philippe.perrin@sxb.bsf.alcatel.fr>
        simple <achatz@forthnet.gr>
        simple <achatz@forthnet.gr>
    Re: simple <josef.moellers@fujitsu-siemens.com>
    Re: simple (Rafael Garcia-Suarez)
    Re: simple <josef.moellers@fujitsu-siemens.com>
    Re: simple <peb@bms.umist.ac.uk>
    Re: simple <achatz@forthnet.gr>
    Re: simple (Rafael Garcia-Suarez)
    Re: simple <bcaligari@fireforged.com>
    Re: sort alphabetically (Anno Siegel)
    Re: Split  (Malcolm Dew-Jones)
    Re: This is not a question ... call me slow if you like <brojek@kis.p.lodz.pl>
    Re: This is not a question ... call me slow if you like <iltzu@sci.invalid>
        unique values in an array - broken algorithm <djberge@uswest.com>
    Re: What's wrong with this code?? (Abigail)
    Re: What's wrong with this code?? <chaos0920@orgio.net>
    Re: What's wrong with this code?? <bart.lateur@skynet.be>
    Re: What's wrong with this code?? <chaos0920@orgio.net>
    Re: What's wrong with this code?? (Villy Kruse)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Aug 2001 00:10:19 -0700
From: circuller@yahoo.com (Nkhouri)
Subject: -w pragma
Message-Id: <64ffc63e.0108192310.11330575@posting.google.com>

i used the -w pragma in my FCGI program ,i get many harmless warnings
like
 used of unintialized values . now if i remove the -w from the shebang
line,
 the program stops responding and writes an error : program terminated
with  exits status 2 . in other words , i cant run the program without
the -w pragma anymore !


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

Date: Mon, 20 Aug 2001 12:29:14 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: -w pragma
Message-Id: <3b810259.2433594423@news.isholf.is>

On 20 Aug 2001 00:10:19 -0700, circuller@yahoo.com (Nkhouri)
wrote:

>i used the -w pragma in my FCGI program ,i get many harmless warnings
>like used of unintialized values . now if i remove the -w from the
>shebang line, the program stops responding and writes an error : 
>program terminated with  exits status 2 . in other words 

> i cant run the program without the -w pragma anymore !

Good.

Regards,
Helgi Briem


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

Date: Mon, 20 Aug 2001 10:27:22 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Copy file in Perl
Message-Id: <3B80D7FA.A16A4538@oracle.com>

This is a multi-part message in MIME format.
--------------5730EC3DEA085A4CF7171AFD
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit



Ernst Wernli wrote:

> Hi,
>
> I've to copy files with PERL. How can I do it?
>
> Exemple:
>
>      N:\temp\test.htm
>      N:\temp\last\test.htm
>
> Thank you
> Ernst

link("N:/temp/test.htm","N:/temp/last/test.htm");

or

link("N:\\temp\\test.htm","N:\\temp\\last\\test.htm");

You can delete files with unlink

Graham Wood

--------------5730EC3DEA085A4CF7171AFD
Content-Type: text/x-vcard; charset=UTF-8;
 name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
 filename="Graham.T.Wood.vcf"

begin:vcard 
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
fn:Graham Wood
end:vcard

--------------5730EC3DEA085A4CF7171AFD--



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

Date: 20 Aug 2001 14:01:49 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Copy file in Perl
Message-Id: <87u1z33v8y.fsf@abra.ru>


GW> Ernst Wernli wrote:

>> Hi,
>> 
>> I've to copy files with PERL. How can I do it?
>> 
>> Exemple:
>> 
>> N:\temp\test.htm
>> N:\temp\last\test.htm
>> 
>> Thank you
>> Ernst

GW> link("N:/temp/test.htm","N:/temp/last/test.htm");

GW> or

GW> link("N:\\temp\\test.htm","N:\\temp\\last\\test.htm");

GW> You can delete files with unlink

First of all link doesn't create a *copy* of file. It just creates
hard link (i.e. another filename for same file).

And I don't expect this to work on Win32 platforms. At least FAT
doesn't support hard links. And hard links doesn't work across
different filesystems too on any OS.

Correct answer: use File::Copy.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Mon, 20 Aug 2001 04:07:48 GMT
From: "abdul  bahar" <BAHA0011@prodigy.net>
Subject: embedding perl in java
Message-Id: <o20g7.1706$ca2.289477810@newssvr17.news.prodigy.com>

Can anyone point me to a good reference or site that has details on how to
embed perl in java?




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

Date: 20 Aug 2001 00:42:56 -0700
From: lafrancefamily@hotmail.com (Greg)
Subject: Error involves unreferenced scalar, unblessed reference. Please help, testcase provided.
Message-Id: <bc79870b.0108192342.258acac6@posting.google.com>

I am getting a strange error, and would appreciate any ideas.

I am using the Win32OLE module that comes with ActiveState's latest
Perl for Windows.
I am using vba in my script to open files in Excel, modify, then save.

How to reproduce:
1) Create three text files, 1.txt, 2.txt, and 3.txt, 
   each on which contains a single line of text:

A,B,C,D,E,F,G

2) Place those three files in a folder named Test on the D drive.
3) Execute this script from within a dos window:

#!perl -w
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;
my ($excel,$file1,$file2,$file3);
$file1='D:\Test\1.txt';
$file2='D:\Test\2.txt';
$file3='D:\Test\3.txt';
$excel = Win32::OLE->new('Excel.Application', 'Quit'); 
$excel->Workbooks->OpenText({FileName => $file1, Origin => xlWindows,
StartRow => 1,
					     DataType => xlDelimited, TextQualifier=>xlDoubleQuote, 
					     ConsecutiveDelimiter=>0, Tab => 0, Semicolon => 0, 
					     Comma => 1, Space => 0, Other => 0, 
					     FieldInfo=>[[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2],
[7, 2]]});
$excel->ActiveSheet->Rows("1:1")->Select;
$excel->Selection->{EntireRow}->{Hidden}=0;	
$excel->ActiveWorkbook->SaveAs({Filename=>'D:\Test\outfile.xls',FileFormat=>xlNormal});
$excel->Sheets->Add;
$excel->Workbooks->OpenText({FileName => $file2, Origin => xlWindows,
StartRow => 1,
					     DataType => xlDelimited, TextQualifier=>xlDoubleQuote, 
					     ConsecutiveDelimiter=>0, Tab => 0, Semicolon => 0, 
					     Comma => 1, Space => 0, Other => 0, 
					     FieldInfo=>[[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2],
[7, 2]]});
$excel->ActiveWorkbook->Save();
$excel->ActiveSheet->Rows("1:1")->Select;
$excel->Selection->{EntireRow}->{Hidden}=1;	
$excel->Sheets->Add();
$excel->Workbooks->OpenText({FileName => $file3, Origin => xlWindows,
StartRow => 1,
					     DataType => xlDelimited, TextQualifier=>xlDoubleQuote, 
					     ConsecutiveDelimiter=>"False", Tab => "False", Semicolon =>
"False",
					     Comma => "True", Space => "False", Other => "False", 
					     FieldInfo=>[[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2],
[7, 2]]});
$excel->ActiveSheet->Rows("1:1")->Select;
$excel->Selection->{EntireRow}->{Hidden}=1;	
$excel->ActiveWorkbook->Save();
$excel->Quit();
undef $excel;

4) When I run this script I get this error:

Attempt to free unreferenced scalar.
Can't call method "Dispatch" on unblessed reference at (eval 1) line
1.
END failed--cleanup aborted.

I really need to solve this problem. Please help if you can. Thanks
very much.
If you could email a solution to lafrancefamily@hotmail.com that would
be
a bonus.

Thanks,
Greg


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

Date: Mon, 20 Aug 2001 10:05:15 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Error involves unreferenced scalar, unblessed reference. Please help, testcase provided.
Message-Id: <3B80C4BB.6000205@post.rwth-aachen.de>

Greg wrote:
> I am getting a strange error, and would appreciate any ideas.

[snipped lot of code]

> $excel->ActiveSheet->Rows("1:1")->Select;
> $excel->Selection->{EntireRow}->{Hidden}=1;	
> $excel->ActiveWorkbook->Save();
> $excel->Quit();
> undef $excel;
> 
> 4) When I run this script I get this error:
> 
> Attempt to free unreferenced scalar.

According to 'perldoc perldiag' this is an internal warning concerning 
the reference counter of a scalar variable. Each Perl-variable 
internally contains an integer that is incremented on each new reference 
that is made to this scalar and decrement if a reference goes away. This 
needed by the Perl garbage-collector to find out when certain data can 
be savely removed from memory.

> Can't call method "Dispatch" on unblessed reference at (eval 1) line
> 1.
> END failed--cleanup aborted.

That's a fatal error....but in your case it happens internally which is 
why you're pretty stuck.

It all looks quite unpleasant really. What I would do is finding a 
maximal subset of your code that runs withouth errors, thus finding out 
which of the above lines would cause this screw-up. And then try to 
eval() the offending line since this "Can't call method..." thing is - 
in theory - trappable.

Since all this happens in cleanup, you might start at the end of your 
script. $excel->Quit() is my most favourite suspect in this case.

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Mon, 20 Aug 2001 10:07:12 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Error involves unreferenced scalar, unblessed reference. Please help, testcase provided.
Message-Id: <3B80C530.9050306@post.rwth-aachen.de>

Greg wrote:

[...]

PS: You should better crosspost if you want your article in several 
newsgroups. Posting twice is not so good since replies would then only 
appear the group where it was replied to


Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Mon, 20 Aug 2001 12:31:37 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Re: Hash of Complex Records
Message-Id: <Jq7g7.2964$uC2.1225798@typhoon1.gnilink.net>

Eric - Thanks, that did it.  Could I have assigned a reference to the array
\@ inside the loop and continued to push new data into it?  Or, does the
array need to filled (i.e., I'm not adding any new elements) before I make
the reference?  I should be able to do it either way, correct?

Thanks again,
Mark



"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9lp67o$6og$1@bob.news.rcn.net...
> Mark Riehl <mark.riehl@agilecommunications.com> wrote:
> > The output didn't work for me, it only printed the vehicle IDs from the
> > outer loop, never entered the inner loop.  I'm wondering if there's a
> > problem on the input side.  Here's what is filling the hash (this is
inside
> > another while, which performs the same task for multiple vehicle ids).
>
>
> >   $rec = {};
> >   $rec->{urn} = $this_urn;
> >   @movement_records = ();
>
> >   while (<INPUT>) {
> >     ... Get the time, lat, long from a file
>
> >     %fields = (time=>$time, latitude=>$latitude, longitude=>$longitude);
> >     push @movement_records, {%fields};
> >   }
>
> >   $LocationData{ $rec->{vid} } = @movement_records;
>
> There's your problem.  An element of a hash can hold only a scalar, not
> an array, so your assignment is taking place in scalar context and what's
> actually being assigned to your hash element is the number of entries in
> @movement_records.  You need to assign a *reference* to @movement_records
> to the hash element; since you seem to have declared it outside your loop,
> the easiest way would be to change @movement_records to
> [@movement_records] in the above assignment (if you had declared it inside
> the loop, you could have written \@movement_records, avoiding making a
> copy).
>




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

Date: 20 Aug 2001 12:48:42 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Hash of Complex Records
Message-Id: <9lr0va$bjc$1@bob.news.rcn.net>

Mark Riehl <mark.riehl@agilecommunications.com> wrote:
> Eric - Thanks, that did it.  Could I have assigned a reference to the array
> \@ inside the loop and continued to push new data into it?  Or, does the
> array need to filled (i.e., I'm not adding any new elements) before I make
> the reference?  I should be able to do it either way, correct?

If you're going to push references created by \@array into another array 
inside a loop, the first array has to be a lexical (my) variable declared 
*inside* the loop.  That ensures that a *different* array will be created 
each time through the loop.  If you use a global, or a lexical defined 
outside the loop, what will happen is that \@array will always be a 
reference to the *same* array and your second array will be full of 
references that all point to the same place, namely the place where the 
last iteration of the loop stuck its data.  That can be a very frustrating 
problem to debug!

The same principle applies to references to scalars and hashes.



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

Date: Mon, 20 Aug 2001 14:42:50 +0200
From: Manuel Klimek <klimek@fmi.uni-passau.de>
Subject: Perl Embed repeated allocation with diagnostics
Message-Id: <3b8105c0@news.rz.uni-passau.de>

Hi there!

Is it possible to generate a PerlInterpreter instance, delete it and then
build a new PerlInterpreter instance if you didn't compile your perl
with -DMULTIPLICITY?
We've written a segfaulting sample prog:
extern "C" {
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
}
#include <iostream>

PerlInterpreter *perlInt;

void start() {
  perlInt = perl_alloc();
  perl_construct(perlInt);

  char *embedding[] = 
    { "", "-w", "-e", "use diagnostics;" }; 
  perl_parse(perlInt, NULL, 4, embedding, NULL);   
  perl_run(perlInt);
  
  PL_perl_destruct_level = 1;
  cout << "destructing..." << flush;
  perl_destruct(perlInt);
  cout << "done" << endl;

  perl_free(perlInt);
}

int main() {
  start(); 
  start(); 

  return 0;
}


The output is:
cordelia:~/stuff/xpertmud/xpertmud 201> ./perl_problem
destructing...done
destructing...Segmentation fault

backtrace:
Starting program: 
/home/tmp/klimek/shadow/xpertmud/xpertmud/xpertmud/./perl_problem
destructing...done
destructing...
Program received signal SIGSEGV, Segmentation fault.
0x4015ae8e in free () from /lib/libc.so.6
(gdb) back
#0  0x4015ae8e in free () from /lib/libc.so.6
#1  0x4015ae19 in free () from /lib/libc.so.6
#2  0x0805a523 in perl_destruct () at eval.c:41
#3  0x08059922 in start () at perl_problem.cc:21
#4  0x08059964 in main () at perl_problem.cc:29
#5  0x400f7237 in __libc_start_main () from /lib/libc.so.6

The question: Is this some general problem or did we do something
wrong?

Thanks for any help,
        Manuel



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

Date: 20 Aug 2001 05:42:42 GMT
From: abigail@foad.org (Abigail)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <slrn9o18r1.ksf.abigail@alexandra.xs4all.nl>

Uri Guttman (uri@sysarch.com) wrote on MMCMXI September MCMXCIII in
<URL:news:x7wv3zgzwm.fsf@home.sysarch.com>:
|| >>>>> "AB" == Alan Barclay <gorilla@elaine.furryape.com> writes:
|| 
||   AB> In article <x7bslpantv.fsf@home.sysarch.com>,
||   AB> Uri Guttman  <uri@sysarch.com> wrote:
||   >> and as others have said, there is little chance of simplifying regular
||   >> expression grammar. it has been around for so many years and nobody has
||   >> come up with a better/simpler grammar.
|| 
||   AB> There have been simpler garmmars, but only at the cost of much of
||   AB> the power. The implementation of regexes you get when using SQL's
||   AB> LIKE operator is very simple, but not very powerful.
|| 
|| well, obviously i mean a simpler grammar for the same power level. i
|| have to steal tad's tag line and say you have to pay for the power. to
|| have perl's regex power, you need to master its grammar (which isn't
|| THAT hard). it just requires some proper thinking.

For regular expressions (as in regular expressions in the Chomsky
hierarchy), all you need is two operators: `*' and `|', and parens for
precedence). `+', `?', `{,}', `[]', `.', etc is all fluff and not at
all needed.

Back references make regular expressions more powerfull. And so do things
like (?{ }).


Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: 20 Aug 2001 13:57:47 CET
From: "Simon Forsell" <simon.forsell@lumumba.com>
Subject: Please advice...
Message-Id: <3b80fb3b$1@news.wineasy.se>

Hello

I have a a page that should display a embedded movie. I need to use perl to
provide the link for this movie, I have already written that simple program
but I want my program to be able to check from which server the request for
this links are made. Because the program is executed by the <embed> tag the
env. variable HTTP_REFERER is not set. How can I check from where the
information is sent?

Any help would be great!

Best regards
Simon





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

Date: Mon, 20 Aug 2001 09:02:22 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: redirecting stdin and stdout
Message-Id: <3B80B5FE.AB9FF403@sxb.bsf.alcatel.fr>

Tarak Parekh wrote:
> What would be the right way to redirect standard out and standard error
> messages from a binary invoked by the system function call ?

If you don't won't to worry about dup commands, you can use the open3()
function in the IPC::Open3 package. It lets you execute a system command
with the appropriate file handles for STDIN, STDOUT and STDERR.

-- 
PhP

($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}


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

Date: Mon, 20 Aug 2001 13:25:44 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
Subject: simple
Message-Id: <3B80E5A8.3F2C7756@forthnet.gr>

I'm sure something similar will have been answered in this newsgroup, but 
i didn't manage to find it :-(.

So here is my question:

I have the following (awfull) awk script (named awk-test):

awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " $12 " " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " " $21 " " $22 " " $23}'

and an input file like this:

str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11


-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

Date: Mon, 20 Aug 2001 13:33:23 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
Subject: simple
Message-Id: <3B80E773.A7877C94@forthnet.gr>

I'm sure something similar will have been answered in this newsgroup, but 
i didn't manage to find it :-(.

So here is my question:

I have the following (awfull) awk script :

awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " $12 " " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " " $21 " " $22 " " $23}'

and an input file like this:

str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12
str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12 str13 str14
str1 str2 str3 str4 str5 str6 str7 str8 str9 str10

the output i'm getting is like this:

str4	str1-str2 str3 str5 str9 str10 str11
str4	str1-str2 str3 str5 str9 str10 str11 str12
str4	str1-str2 str3 str5 str9 str10 str11 str12 str13 str14
str4	str1-str2 str3 str5 str9 str10

PS: each line's str is different (str1 on line1 is different from str1 on line2) 
and each line contains different number of strings (line1 contains 11 strings, line2 contains 12 strings....)

How can i implement this in perl?

-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

Date: Mon, 20 Aug 2001 12:35:35 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: simple
Message-Id: <3B80E7F7.8384A42@fujitsu-siemens.com>

Tassos Chatzithomaoglou wrote:
> =

> I'm sure something similar will have been answered in this newsgroup, b=
ut
> i didn't manage to find it :-(.
> =

> So here is my question:
> =

> I have the following (awfull) awk script (named awk-test):
> =

> awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " =
$12 " " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " "=
 $21 " " $22 " " $23}'
> =

> and an input file like this:
> =

> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11

The answer is simple: "42".

SCNR, but what _is_ your question?

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: 20 Aug 2001 10:47:20 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: simple
Message-Id: <slrn9o1r04.od.rgarciasuarez@rafael.kazibao.net>

Tassos Chatzithomaoglou wrote in comp.lang.perl.misc:
} I'm sure something similar will have been answered in this newsgroup, but 
} i didn't manage to find it :-(.
} 
} So here is my question:
} 
} I have the following (awfull) awk script :
    [...]
} How can i implement this in perl?

Perl comes with an awk to perl translator, a2p. See the docs for it. You
can then study a2p output and "prettify" it.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 20 Aug 2001 13:03:18 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: simple
Message-Id: <3B80EE76.2149255@fujitsu-siemens.com>

Tassos Chatzithomaoglou wrote:
> =

> I'm sure something similar will have been answered in this newsgroup, b=
ut
> i didn't manage to find it :-(.
> =

> So here is my question:
> =

> I have the following (awfull) awk script :
> =

> awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " =
$12 " " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " "=
 $21 " " $22 " " $23}'
> =

> and an input file like this:
> =

> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12 str13 st=
r14
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10
> =

> the output i'm getting is like this:
> =

> str4    str1-str2 str3 str5 str9 str10 str11
> str4    str1-str2 str3 str5 str9 str10 str11 str12
> str4    str1-str2 str3 str5 str9 str10 str11 str12 str13 str14
> str4    str1-str2 str3 str5 str9 str10
> =

> PS: each line's str is different (str1 on line1 is different from str1 =
on line2)
> and each line contains different number of strings (line1 contains 11 s=
trings, line2 contains 12 strings....)
> =

> How can i implement this in perl?

while (<STDIN>) {
    split /\s+/;
    print "$_[3]\t$_[0]-$_[1] $_[2] $_[4] ... etc\n";
}

Note that awk's indices start at 1 while perl's start at 0.
Also note that TMTOWTDI.

HTH,

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Mon, 20 Aug 2001 12:52:34 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: simple
Message-Id: <3B80FA02.C83F80C@bms.umist.ac.uk>

Tassos Chatzithomaoglou wrote:
> 
> I'm sure something similar will have been answered in this newsgroup, but
> i didn't manage to find it :-(.
> 
> So here is my question:
> 
> I have the following (awfull) awk script :
> 
> awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " $12 " " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " " $21 " " $22 " " $23}'
> 
> and an input file like this:
> 
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12 str13 str14
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10
> 
> the output i'm getting is like this:
> 
> str4    str1-str2 str3 str5 str9 str10 str11
> str4    str1-str2 str3 str5 str9 str10 str11 str12
> str4    str1-str2 str3 str5 str9 str10 str11 str12 str13 str14
> str4    str1-str2 str3 str5 str9 str10
> 
> PS: each line's str is different (str1 on line1 is different from str1 on line2)
> and each line contains different number of strings (line1 contains 11 strings, line2 contains 12 strings....)
> 
> How can i implement this in perl?

perl -ne '@line = split; print "$line[3]\t$line[0]-$line[1] $line[2]
$line[4] ", join(" ", @line[8..$#line]), "\n";' <filename>

HTH

Paul


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

Date: Mon, 20 Aug 2001 15:05:27 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
To: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: simple
Message-Id: <3B80FD07.5B193348@forthnet.gr>



Paul Boardman wrote:
> 
> Tassos Chatzithomaoglou wrote:
> >
> > I'm sure something similar will have been answered in this newsgroup, but
> > i didn't manage to find it :-(.
> >
> > So here is my question:
> >
> > I have the following (awfull) awk script :
> >
> > awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " $12 " " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " " $21 " " $22 " " $23}'
> >
> > and an input file like this:
> >
> > str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
> > str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12
> > str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11 str12 str13 str14
> > str1 str2 str3 str4 str5 str6 str7 str8 str9 str10
> >
> > the output i'm getting is like this:
> >
> > str4    str1-str2 str3 str5 str9 str10 str11
> > str4    str1-str2 str3 str5 str9 str10 str11 str12
> > str4    str1-str2 str3 str5 str9 str10 str11 str12 str13 str14
> > str4    str1-str2 str3 str5 str9 str10
> >
> > PS: each line's str is different (str1 on line1 is different from str1 on line2)
> > and each line contains different number of strings (line1 contains 11 strings, line2 contains 12 strings....)
> >
> > How can i implement this in perl?
> 
> perl -ne '@line = split; print "$line[3]\t$line[0]-$line[1] $line[2]
> $line[4] ", join(" ", @line[8..$#line]), "\n";' <filename>
> 
> HTH
> 
> Paul

thx a lot, that seems to work fine...

-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

Date: 20 Aug 2001 12:06:06 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: simple
Message-Id: <slrn9o1vjp.un.rgarciasuarez@rafael.kazibao.net>

Paul Boardman wrote in comp.lang.perl.misc:
} 
} perl -ne '@line = split; print "$line[3]\t$line[0]-$line[1] $line[2]
} $line[4] ", join(" ", @line[8..$#line]), "\n";' <filename>
			^^^^^^^^^^^^^^^^
You can interpolate this in the double-quoted string and avoid the
join().
					   ^^^^
You can also leave the "\n" if you use the -l command-line switch.
-l also chomps the input lines. This may be useful (not here, because
the split on whitespace also wipes out the trailing \n from the last
field).

You can also completely drop the split by using -a.
perlrun gives details on command-line switches.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 20 Aug 2001 13:57:57 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: simple
Message-Id: <9lqtnq0qrf@enews2.newsguy.com>


"Tassos Chatzithomaoglou" <achatz@forthnet.gr> wrote in message
news:3B80E5A8.3F2C7756@forthnet.gr...

> awk '{print $4 "\t" $1 "-" $2 " " $3 " " $5 " " $9 " " $10 " " $11 " " $12
" " $13  " " $14 " " $15 " " $16 " " $17 " " $18  " " $19 " " $20 " " $21 "
" $22 " " $23}'
>
> and an input file like this:
>
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
> str1 str2 str3 str4 str5 str6 str7 str8 str9 str10 str11
>

perl -ne '@a=split; print("$a[3]\t$a[0]-", join(" ", (@a)[1,2,4,8..$#a]),
"\n")' filename

This should do the trick

awk is good especially for 'small' stuff

Brendon
++++






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

Date: 20 Aug 2001 11:35:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sort alphabetically
Message-Id: <9lqsmo$itj$1@mamenchi.zrz.TU-Berlin.DE>

According to Stephen Deken <shutupsteve@awdang.no.thanks.com>:
> "greg" <benz@op.net> wrote:
> > I'm having a hard time trying to find out how to sort
> > alphabetically, i have two fields, title and text and
> > i'm trying to sort alphabetically by the title field.
> 
> Ten million people on this mailing list will tell you to check the FAQ, but
> I'm bored, so I'll educate you.
 
"This" is comp.lang.perl.misc, not a mailing list but a Usenet group.

The people who answer frequently asked questions with a pointer to the
FAQ have a reason:  The FAQ is usually correct.

> Perl has a built-in sort:
> 
>   my @sorted = sort @array;
> 
> You can optionally specify how to sort with a block of code:
> 
>   my @sorted = sort { $a cmp $b } @array;
> 
> This will sort @array alphabetically, because the { $a cmp $b } part tells
> perl to compare $a and $b (which are two elements in the array)
> lexographically instead of numerically.
  ^^^^^^^^^^^^^^^
You are implying that the default sort order is numeric.  Please look
up sort in perlfun.  You will find that the default sort order is
lexicographic (not lexographic).

>                                          In your case, you need to carry
> around another bit of information - the rest of the line.  So you have to
> put it into a hash.

Why do you think so?  Nothing the OP has said indicates that any part
of the information is usable as a hash key.  For all we know, you'd
lose information that way.

[rest snipped]

If you answer a FAQ with your own solution, be sure your solution has
anything to offer beyond the FAQ list.  Be double sure that your answer
isn't misleading or plain wrong.

Anno


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

Date: 19 Aug 2001 23:35:24 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Split 
Message-Id: <3b80afac@news.victoria.tc.ca>

Asgar (asgar@tkusa.com) wrote:
: a newbie here:
: I am reading a file of fields separated by space:

: while (<FILEH>)
: ($a, $b, $c, ....) = split (/ /);  # Total of 23 fields

: # Doing some stuff & writing it back to another file:

: print OUTPUTFILE "$a $b $c ...."

: Everything works fine, except that I am getting the first
: 9 fields written back into the output file.
: what am doing wrong?
: Thanks for any input.


$0.02 

how do you know the incoming data has all 23 fields full of data?

how do you know the written data has only nine fields of data.

Have you seen a Hex dump of the data before and after, so as to count the
fields and see the line endings?  Have you asked the perl to dump some
kind of ascii dump of the data before ane after the split? 



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

Date: 20 Aug 2001 11:51:22 GMT
From: Przemyslaw Brojewski <brojek@kis.p.lodz.pl>
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <9lqtjq$mnd$1@kujawiak.man.lodz.pl>

I get:
Modification of a read-only value attempted at cosik line 2.

perl 5.6.1.

what gives?


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

Date: 20 Aug 2001 12:45:50 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <998311456.28496@itz.pp.sci.fi>

In article <9lqtjq$mnd$1@kujawiak.man.lodz.pl>, Przemyslaw Brojewski wrote:
>I get:
>Modification of a read-only value attempted at cosik line 2.
>
>perl 5.6.1.

Sorry.  Try the one in my .sig -- the original breaks under perl v5.6.

-- 
# Ilmari Karonen -- http://www.sci.fi/~iltzu/
s''n4|9|21|3|n1\2||2|(_-<2_|4_`1|3\3_1\2_|3\3-_)2_|n\__/\_,_|___/\__|2\__,_|_|
1_|\___/\__|_|1_|\___|_|nn4_1\9|3|14|n4__/1-_)2_|1|5\3_`1|2_|1!1/2-_)2_|n3_|1\
___|_|2_|2_|1_|\__,_|\__|_i_\\\___|_|1)n45/n',y/n\n/\n/d,s/\d+/$"x$&/eg,print;




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

Date: Mon, 20 Aug 2001 08:02:31 -0500
From: Mr Sunblade <djberge@uswest.com>
Subject: unique values in an array - broken algorithm
Message-Id: <3B810A67.3B2DDCE4@uswest.com>

Hi all,

Someone posted this technique for extracting unique elements out of an
array, but there's a syntax error somewhere.  I've futzed with it a bit,
couldn't get it right.  Any takers?

my @array = qw(1 2 3 4 5 2 3 4);
my @uniq = keys %{ map { $_, 1 } @array};

Ambiguous use of %{map{...}} resolved to %map{...} at ./maptest.pl line
 ...

Thanks in advance.

Regards,

Mr. Sunblade

--
"Evil will always triumph because Good is *dumb*."
-- Dark Helmet, 'Spaceballs: The Movie'





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

Date: 20 Aug 2001 05:47:14 GMT
From: abigail@foad.org (Abigail)
Subject: Re: What's wrong with this code??
Message-Id: <slrn9o193h.ksf.abigail@alexandra.xs4all.nl>

Seung Choi (chaos0920@orgio.net) wrote on MMCMXI September MCMXCIII in
<URL:news:Xns9102EAB7514D2chaos0920orgionet@199.45.45.11>:
// Bart Lateur <bart.lateur@skynet.be> wrote in 
// news:cot0ot4koth9sg884ug226g5fjf0bs6eri@4ax.com:
// 
// > Seung Choi wrote:
// > 
// >>I need help on the code below.
// >>
// >>$var1 = qw{<tr bgcolor="RGB(200,230,200)">};
// >>
// >>when I put this variable into the html code, it only puts
// >>'bgcolor="RGB(200,230,200)">' and omits <tr part. 
// > 
// > Why are you using "qw"? I think you want "q", or maybe "qq" (no
// > difference in this example). "qw" splits on whitespace into a list, of
// > which you only use the last item.
// > 
// 
// 
// Thanks all you guys for helping me out.
// 
// I resolved the problem I had based on what you guys had told me.


You could have helped yourself. Had you use -w, your code would not have
received one warning, your code would not have received two warnings,
no, your faulty code would have received *THREE* warnings.

Always, always, always run your code with warnings enabled. There is no
excuse.


Abigail
-- 
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
          q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'


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

Date: Mon, 20 Aug 2001 10:40:21 GMT
From: Seung Choi <chaos0920@orgio.net>
Subject: Re: What's wrong with this code??
Message-Id: <Xns91034369A6717chaos0920orgionet@199.45.45.11>

Thanks for your advice, Abigail.

and about using -w flag, I have a question on how to use it since I'm only a 
beginner.
The perl script was CGI and how can I run it (or test if it's working) 
unless I update on the server and test it? I obviously (I think) can't put 
any additional command-line compiler flags when I have to test it on server.


My question is, is there a better way to develop the CGI script and test it 
with perl compiler instead of having to update it on the server and test it?
If there is, it would really help me making next one.

Thanks in advance.


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

Date: Mon, 20 Aug 2001 11:24:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: What's wrong with this code??
Message-Id: <res1otksp2b77v2fjc8itpt5c1l7qdei7g@4ax.com>

Seung Choi wrote:

>and about using -w flag, I have a question on how to use it since I'm only a 
>beginner.
>The perl script was CGI and how can I run it (or test if it's working) 
>unless I update on the server and test it? I obviously (I think) can't put 
>any additional command-line compiler flags when I have to test it on server.

You can put it on the shebang line (the very ffirst line in the script,
the one that points to the "interpreter"). For example, if that ine was

	#!/usr/local/bin/perl

change it to

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


When used in CGI, you might have some practical difficulties, as
warnings are printed to STDERR and that commonly gets into the
webserver's error log, not into the browser window. There are some ways
around that, I think that the module CGI::Carp can help.
"warningsToBrowser" looks very nice. That way, it looks like you can
embed warnings as HTML comments in your code.

-- 
	Bart.


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

Date: Mon, 20 Aug 2001 11:30:04 GMT
From: Seung Choi <chaos0920@orgio.net>
Subject: Re: What's wrong with this code??
Message-Id: <Xns91034BD7CDFF9chaos0920orgionet@199.45.45.11>


Thank you Bart, but when you say 'CGI::Carp' or '"waringsToBrowser",

where can I find those information from?


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

Date: 20 Aug 2001 12:02:17 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: What's wrong with this code??
Message-Id: <slrn9o1v29.fvm.vek@pharmnl.ohout.pharmapartners.nl>

On Mon, 20 Aug 2001 10:40:21 GMT,
    Seung Choi <chaos0920@orgio.net> wrote:


>Thanks for your advice, Abigail.
>
>and about using -w flag, I have a question on how to use it since I'm only a 
>beginner.
>The perl script was CGI and how can I run it (or test if it's working) 
>unless I update on the server and test it? I obviously (I think) can't put 
>any additional command-line compiler flags when I have to test it on server.
>


I would suggest to download perl from a cpan archive and install it.
There are quite a few mirror of that archive you can use, see
www.cpan.org.

www.activestate.com would not be a bad place to start if you are
running a win9x or NT PC.  There you find the latest version for
win9x/NT systems ready for download.

Installing perl on your own system is a MUST IMHO if you are going to
develop perl programs.


Villy


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

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.  

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


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