Autodocumented DATA parts

2 views
Skip to first unread message

gamo

unread,
Aug 20, 2021, 8:23:15 AMAug 20
to

Hi there!

Suppose I'm using 2 files of CSV data to perform
a simple calculation, and I want to include the
data in the script file for better handling and
publishing. Ideally it would look like this

#!/usr/bin/perl -W

while (<DATA1>){
}
while (<DATA2>){
}

say "blah";

exit 1;

__DATA1__
1, 2
3, 4
__DATA2__
2, 4
6, 8
__END__

Is it possible somewhat with a subversion of perl > 5.030?

TIA


--
http://gamo.sdf-eu.org/
perl -E 'say "use v5;"'

gamo

unread,
Aug 20, 2021, 3:21:39 PMAug 20
to
El 20/8/21 a las 14:23, gamo escribió:
>
> Hi there!
>
> Suppose I'm using 2 files of CSV data to perform
> a simple calculation, and I want to include the
> data in the script file for better handling and
> publishing. Ideally it would look like this
>
> #!/usr/bin/perl -W
>
> while (<DATA1>){
> }
> while (<DATA2>){
> }
>
> say "blah";
>
> exit 1;
>
> __DATA1__
> 1, 2
> 3, 4
> __DATA2__
> 2, 4
> 6, 8
> __END__
>
> Is it possible somewhat with a subversion of perl > 5.030?
>
> TIA
>
>


Funny thing, this can be done with a different redaction of the
program. Not much sure if the data readed in a two dimensional
array is as useful as data in two or three or... single lists.
So the question could be reformulated as this can be done
without 2D arrays.

#!/usr/bin/perl -W

use strict;

my $files = 1000;

my $data = 0;

my @array;

open IN, '<', $0 or die $!;
while (<IN>){
if (/__DATA(\d+)__/) { $data = $1; }
if (/__END__/) { $data = 0; }
push @{ $array[$data] }, $_ if $data > 0;
}
close IN;

exit 1;

__END__

__DATA1__
1 , 2
3 , 4
__DATA2__
2 , 4
6 , 8
__END__





--
http://gamo.sdf-eu.org/
perl -E 'say "Don't try this at localhost."'

Eric Pozharski

unread,
Aug 23, 2021, 1:33:13 PMAug 23
to
with <sfovbs$1qv3$1...@gioia.aioe.org> gamo wrote:
> El 20/8/21 a las 14:23, gamo escribió:

*SKIP*
> Funny thing, this can be done with a different redaction of the
> program. Not much sure if the data readed in a two dimensional array
> is as useful as data in two or three or... single lists. So the
> question could be reformulated as this can be done without 2D arrays.

What you are doing here is, effectevely, inventing your own
serialization. And as long as it's not my problem, it's fine with me.
However,

*SKIP*
> while (<IN>){
> if (/__DATA(\d+)__/) { $data = $1; }
> if (/__END__/) { $data = 0; }
> push @{ $array[$data] }, $_ if $data > 0;
> }

here you're pushing '__DATA000__' on target arrays ('000' is a
placeholder). But, you probably already know that. May I introduce you
to fine, already existing, and widely supported world of YAML?

=== contents (/home/whynot/foo.j99FmL.pl) goes below ===
#!/usr/bin/perl

use strict;
use warnings;

use YAML::Tiny;
use Data::Printer;

my $data = join "\n", DATA->getlines;
$data = YAML::Tiny->read_string( $data )->[0];

p $data;

__DATA__
---
-
- 1, 2
- 3, 4
-
- 2, 4
- 6, 8
...
__END__
=== contents (/home/whynot/foo.j99FmL.pl) gone above ===

However, per your request, here comes unwiding into arbitrary *list*
(not *ARRAY*) of arrays (also, I suppose that exploiting CSV is just
another layer of serialization; with YAML you don't need that!)

=== contents (/home/whynot/foo.rwxOo1.pl) goes below ===
#!/usr/bin/perl

use strict;
use warnings;

use YAML::Tiny;
use Data::Printer;

my $data = join "\n", DATA->getlines;
$data = YAML::Tiny->read_string( $data )->[0];

my( @fix_cwhm, @fix_fnxa );
@$_ = @{ shift @$data } foreach \@fix_cwhm, \@fix_fnxa;

p @fix_cwhm;
p @fix_fnxa;

__DATA__
---
-
-
- 1
- 2
-
- 3
- 4
-
-
- 2
- 4
-
- 6
- 8
...
__END__
=== contents (/home/whynot/foo.rwxOo1.pl) gone above ===

*CUT*

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Eli the Bearded

unread,
Aug 23, 2021, 2:36:46 PMAug 23
to
In comp.lang.perl.misc, Eric Pozharski <why...@pozharski.name> wrote:
> But, you probably already know that. May I introduce you
> to fine, already existing, and widely supported world of YAML?

s/fine, //

It works, but it's really a pain. Someone looked at Python's whitespace
sensitivity and thought "Dang, that'd make a great data structure!"
neglecting to remember that data structures are rarely as easy to
break down into smaller blocks as functions are.

This looks not too bad, but making sure you have the indentation
right when you're backing down to a level scrolled off screen
is annoying, and when you've on the configure the creation instead
of configure the access side of things, and start including screenfuls
of certificates, and/or using some sort of encrypt-values-in-place
scheme for sensitive stuff that needs to get checked in to source
control, and suddenly you need a linter just for data serialization.

group:
clients:
colo:
fra1:
endpoints:
redis:
host: foo.bar.example.com
port: 8000
password: "exoticstring"
database: 2
elasticsearch: &fra1-shared-elasticsearch
host: qux.bar.example.com
port: 7000
username: search_user
password: "strangestring"
mysql:
host: baz.bar.example.com
port: 9000
username: rw_user
password: "longstring"
mysql_read:
host: baz.bar.example.com
port: 9001
username: ro_user
password: "funnystring"
pdx1:
endpoints:
redis:
host: foo.boo.example.com
port: 8000
password: "exoticphrase"
database: 2
elasticsearch:
host: qux.boo.example.com
port: 7000
username: search_user
password: "strangephrase"
mysql:
host: baz.boo.example.com
port: 9000
username: rw_user
password: "longphrase"
mysql_read:
host: baz.boo.example.com
port: 9001
username: ro_user
password: "funnyphrase"
public:
colo:
fra1:
endpoints:
redis:
host: foo.bar.example.com
port: 8000
password: "exotictext"
database: 1
elasticsearch: *fra1-shared-elasticsearch
mysql:
host: baz.bar.example.com
port: 9002
username: rw_user
password: "longtext"
mysql_read:
host: baz.bar.example.com
port: 9003
username: r0_user
password: "funnytext"

Not to mention "Oh yeah, JSON is is a valid YAML format, too."

Elijah
------
still better than Terrafom's progamming language disguised as data structure

gamo

unread,
Aug 23, 2021, 4:43:07 PMAug 23
to
El 23/8/21 a las 20:36, Eli the Bearded escribió:

[YAML or JSON]

> still better than Terrafom's progamming language disguised as data structure

Got it.
How about this redaction? Which is the least sucker way?

use strict;
no strict 'refs';

my @names = "A".."Z"; # there are single letters that can't be
# used with strict
my $data = 0;
open IN, '<', $0 or die $!;
while (<IN>){
if (/__DATA(\d+)__/) {
$data = $1;
}
if (/__END__/) { $data = 0; }
push @{ $array[$data] }, $_ if $data > 0; # option Z
push @{ ${ "$names[$data]" } }, $_ if $data > 0; # option A
push @{ "$names[$data]" }, $_ if $data > 0; # option B
}
close IN;

Thanks for your comments!

Postdata: I find perlcritic is less critic than I would like.
Maybe I'm expecting 'perlexplain'

--
http://gamo.sdf-eu.org/
perl -E 'say "It's Java? wow! champaigne!"'

Eric Pozharski

unread,
Aug 24, 2021, 1:33:12 PMAug 24
to
with <sg118k$19sh$1...@gioia.aioe.org> gamo wrote:
> El 23/8/21 a las 20:36, Eli the Bearded escribió:

*SKIP*
> if (/__DATA(\d+)__/) {
> $data = $1;
> }

Doubts start to creep in. Here you're still pushing '__DATA000__' onto
your arrays. Are you really running your code?

Eric Pozharski

unread,
Aug 24, 2021, 1:33:13 PMAug 24
to
with <sfo6rd$1mi$1...@gioia.aioe.org> gamo wrote:

> Hi there!

I see it clearly now. Abort everything, put in __DATA__ perl
expression(s), read it, then eval what you've just read. Problem
solved.

Eric Pozharski

unread,
Aug 24, 2021, 1:33:14 PMAug 24
to
with <eli$21082...@qaz.wtf> Eli the Bearded wrote:
> In comp.lang.perl.misc, Eric Pozharski <why...@pozharski.name> wrote:

>> But, you probably already know that. May I introduce you to fine,
>> already existing, and widely supported world of YAML?
>
> s/fine, //
>
> It works, but it's really a pain. Someone looked at Python's
> whitespace sensitivity and thought "Dang, that'd make a great data
> structure!" neglecting to remember that data structures are rarely as
> easy to break down into smaller blocks as functions are.

I understand that inventing serialization on spot is way to go. I see
how it's going right now in this very thread.

*SKIP*
> Not to mention "Oh yeah, JSON is is a valid YAML format, too."

Are you pushing for XML? I'm confused.

> still better than Terrafom's progamming language disguised as data
> structure

I'm not exposed, but I have sense of frustration anyway.

gamo

unread,
Aug 24, 2021, 10:44:45 PMAug 24
to
El 24/8/21 a las 16:06, Eric Pozharski escribió:
> Doubts start to creep in. Here you're still pushing '__DATA000__' onto
> your arrays. Are you really running your code?

Nope. It's only a concept. But since I could code __DATA1__ and insert
a csv, for example, I would not commit the error of using __DATA0__

However I could not comprehend why you (plural) are so reluctant to use
a script to carry data, since shell batch .sh files could be arranged
into .shar archives. Not the best desing in the universe, but it's done.

--
http://gamo.sdf-eu.org/
perl -E 'say "Error: this is premium error. Dividing 0/0."'

Eric Pozharski

unread,
Aug 25, 2021, 1:33:11 PMAug 25
to
with <sg4aqn$7sv$1...@gioia.aioe.org> gamo wrote:
> El 24/8/21 a las 16:06, Eric Pozharski escribió:
>> Doubts start to creep in. Here you're still pushing '__DATA000__'
>> onto your arrays. Are you really running your code?
> Nope. It's only a concept. But since I could code __DATA1__ and insert
> a csv, for example, I would not commit the error of using __DATA0__

So those are safety tags now. Somehow defies purpose of zoo of arrays
then.

> However I could not comprehend why you (plural) are so reluctant to
> use a script to carry data, since shell batch .sh files could be
> arranged into .shar archives. Not the best desing in the universe, but
> it's done.

IMHO, you're misinterpreting observations.

gamo

unread,
Aug 25, 2021, 5:54:29 PMAug 25
to
El 25/8/21 a las 12:34, Eric Pozharski escribió:
>>> Doubts start to creep in. Here you're still pushing '__DATA000__'
>>> onto your arrays. Are you really running your code?

>> Nope. It's only a concept. But since I could code __DATA1__ and insert
>> a csv, for example, I would not commit the error of using __DATA0__

> So those are safety tags now. Somehow defies purpose of zoo of arrays
> then.
>
Maybe. Look at the latest version to say if it's 'workable' or not.

#!/usr/bin/perl -w

use strict;
# no strict 'refs';

# my @names = "A".."Z"; # there are single letters that can't be
used with strict
# my $files = scalar(@names);

my $data = 0;

my @array;

open IN, '<', $0 or die $!;
while (<IN>){
if (/__DATA(\d+)__/) {
$data = $1;
next;
}
if (/__END__/) { $data = 0; }
push @{ $array[$data] }, $_ if $data > 0;
# push @{ ${ "$names[$data]" } }, $_ if $data > 0;
# push @{ "$names[$data]" }, $_ if $data > 0;
}
close IN;

USE:

my $fd = 1; # file descriptor number
my $fc ; # file content

$fc = $array[$fd];
for (@$fc) {
# Here you have your first file, line by line
print $_;
}
print "Done $fd\n";
$fc = $array[++$fd];
for (@$fc){
# Second file
print $_;
}
print "Done $fd\n";
$fc = $array[++$fd];
for (@$fc){
print $_;
}
print "Done $fd\n";


exit 1;

__END__

__DATA1__
1 , 2
3 , 4
__DATA2__
2 , 4
6 , 8
__DATA3__
3 , 5
7 , 9
__END__



--
http://gamo.sdf-eu.org/
perl -E 'say "Error: TZ 24 hours wrong."'

Keith Thompson

unread,
Aug 25, 2021, 6:42:11 PMAug 25
to
gamo <ga...@telecable.es> writes:
> El 25/8/21 a las 12:34, Eric Pozharski escribió:
>>>> Doubts start to creep in. Here you're still pushing '__DATA000__'
>>>> onto your arrays. Are you really running your code?
>
>>> Nope. It's only a concept. But since I could code __DATA1__ and insert
>>> a csv, for example, I would not commit the error of using __DATA0__
>
>> So those are safety tags now. Somehow defies purpose of zoo of arrays
>> then.
>>
> Maybe. Look at the latest version to say if it's 'workable' or not.
>
> #!/usr/bin/perl -w
>
> use strict;
> # no strict 'refs';
>
> # my @names = "A".."Z"; # there are single letters that can't
> be used with strict

It looks like your news posting software wrapped lines, which in this
case introduced a syntax error. Consider keeping your source code below
about 72 columns, at least if you're going to post it here.

> # my $files = scalar(@names);
>
> my $data = 0;
>
> my @array;
>
> open IN, '<', $0 or die $!;

Is it guaranteed that $0 gives you a file name you can open? It does in
the cases I've checked, but for example if the script is named "foo" and
it's a directory in your $PATH, I don't see a guarantee that it will
give you the full path name.

In any case, you already have the DATA filehandle, which gives you
content starting at __END__. Why not just use that?

Of course you can use whatever markers you like in the lines after
__END__.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

gamo

unread,
Aug 25, 2021, 8:47:42 PMAug 25
to
El 26/8/21 a las 0:42, Keith Thompson escribió:
> Is it guaranteed that $0 gives you a file name you can open? It does in
> the cases I've checked, but for example if the script is named "foo" and
> it's a directory in your $PATH, I don't see a guarantee that it will
> give you the full path name.


You are right. To cover all the corners I must use $zero or a workaround
to check

if (-e $0){ ; }

#/usr/bin/perl -w
use 5.030;
say "$0";
my $full = `which $0`;
say "$full";
my $zero = $full // $0;
exit 1;


--
http://gamo.sdf-eu.org/
perl -E 'say "This hurts!"'

gamo

unread,
Aug 25, 2021, 9:29:33 PMAug 25
to
El 26/8/21 a las 2:47, gamo escribió:
chomp ($full);
my $zero = length($full) > length($0) ? $full : $0;

open IN, '<', $zero or die $!;

Hope this works.

--
http://gamo.sdf-eu.org/
perl -E 'say "Guess what?"'

gamo

unread,
Aug 25, 2021, 10:58:03 PMAug 25
to
El 26/8/21 a las 3:29, gamo escribió:
> perl -E 'say "Guess what?"'

Finally I realized that data inside the script could be
loaded at first, whithout problem, in an arbitrary amount
of distincts variables.

So this version avoid all problems related to autoparse.

#!/usr/bin/perl -w

use strict;

my $data1 = <<EOT;
1 , 2
3 , 4
EOT
;

my $c = 0;
for (split /\n/, $data1){
print "$_\n";
$c++;
}
print "$c lines proccessed\n";

exit 1;




--
http://gamo.sdf-eu.org/
perl -E 'say "KISS rules!"'

Keith Thompson

unread,
Aug 26, 2021, 1:06:27 AMAug 26
to
Actually I'm not sure that's necessary. In all cases I've tried, Perl's
$0 gives you the full path to the script, even if you invoked it via
$PATH. (The cases I've tried are Ubuntu and Cygwin, both POSIX-like
environments.)

Bash's $0 behaves the same way. C's argv[0] (again, in the cases I've
tried) gives you the string used to invoke the command, not necessarily
its full path.

`perldoc perlvar` says it "Contains the name of the program being
executed" -- which leaves open the question of what "the name" means.

Perhaps there's a guarantee somewhere that I haven't found.

I don't quite trust the `which` command to do the right thing in all
cases, though perhaps that's paranoid.

But in any case, you're using $0 to read from the current script, when
as far as I can tell the DATA filehandle, which starts after __END__ or
__DATA__, is a much cleaner way to do what you're trying to do. You
wouldn't have to worry about the behavior of $0. Why is <DATA> not
suitable for your purpose?

gamo

unread,
Aug 26, 2021, 3:23:39 AMAug 26
to
El 26/8/21 a las 7:06, Keith Thompson escribió:
> You
> wouldn't have to worry about the behavior of $0. Why is <DATA> not
> suitable for your purpose?

Thank you for both assertions.
The only problem about __DATA__ is that is unique. One file, i.e.
So first thing I think is to do it multiple.
But I could be wrong, because yo can put the info both at the end
of the code or inside the code at the begining so look for my
keep it simple last alternative.

Cheers.

--
http://gamo.sdf-eu.org/
perl -E 'say "Two wrongs one good. I'm qualified?"'

Eric Pozharski

unread,
Aug 26, 2021, 5:33:13 AMAug 26
to
with <87eeahg...@nosuchdomain.example.com> Keith Thompson wrote:
> gamo <ga...@telecable.es> writes:
>> El 25/8/21 a las 12:34, Eric Pozharski escribió:

*SKIP*
>> my $data = 0;
>> my @array;
>> open IN, '<', $0 or die $!;
>
> Is it guaranteed that $0 gives you a file name you can open? It does
> in the cases I've checked, but for example if the script is named
> "foo" and it's a directory in your $PATH, I don't see a guarantee that
> it will give you the full path name.
>
> In any case, you already have the DATA filehandle, which gives you
> content starting at __END__. Why not just use that?

@All For those interested in '__DATA__', please search for 'Special
Literals' in 'perldoc perldata' -- important details have been discussed
over there.

> Of course you can use whatever markers you like in the lines after
> __END__.

@gamo You didn't address the main point. Can you re-invent '__DATA__'?
Sure you can. Can you workaround your re-invention? Totally. And
still. Sometimes, there're places in your Hero's Journey where you just
must keep your NIH at bay. Just read the fscking DATA, it's already
there.

gamo

unread,
Aug 26, 2021, 7:26:43 AMAug 26
to
El 26/8/21 a las 10:45, Eric Pozharski escribió:
> You didn't address the main point. Can you re-invent '__DATA__'?
> Sure you can. Can you workaround your re-invention? Totally. And
> still. Sometimes, there're places in your Hero's Journey where you just
> must keep your NIH at bay. Just read the fscking DATA, it's already
> there.

Pollaski, huh, get your toxicity and negativity and give it to another
target. By the way, Perl is still better than... name it, and doesn't
deserve pyscho-users patronizing others over 'timtowtdi'.

--
http://gamo.sdf-eu.org/
perl -E 'say "Bullshit pool empty!"'

Keith Thompson

unread,
Aug 26, 2021, 4:37:11 PMAug 26
to
gamo <ga...@telecable.es> writes:
> El 26/8/21 a las 10:45, Eric Pozharski escribió:
>> You didn't address the main point. Can you re-invent '__DATA__'?
>> Sure you can. Can you workaround your re-invention? Totally. And
>> still. Sometimes, there're places in your Hero's Journey where you just
>> must keep your NIH at bay. Just read the fscking DATA, it's already
>> there.
>
> Pollaski, huh, get your toxicity and negativity and give it to another
> target. By the way, Perl is still better than... name it, and doesn't
> deserve pyscho-users patronizing others over 'timtowtdi'.

I was just about to offer a (hopefully) helpful followup, but after
reading this I've decided not to. You overreacted to Eric's valid
criticism. I believe you're probably wasting your time, but I'm no
longer inclined to help.

gamo

unread,
Aug 27, 2021, 6:47:57 AMAug 27
to
El 26/8/21 a las 22:37, Keith Thompson escribió:
> gamo <ga...@telecable.es> writes:
>> El 26/8/21 a las 10:45, Eric Pozharski escribió:
>>> You didn't address the main point. Can you re-invent '__DATA__'?
>>> Sure you can. Can you workaround your re-invention? Totally. And
>>> still. Sometimes, there're places in your Hero's Journey where you just
>>> must keep your NIH at bay. Just read the fscking DATA, it's already
>>> there.
>>
>> Pollaski, huh, get your toxicity and negativity and give it to another
>> target. By the way, Perl is still better than... name it, and doesn't
>> deserve pyscho-users patronizing others over 'timtowtdi'.
>
> I was just about to offer a (hopefully) helpful followup, but after
> reading this I've decided not to. You overreacted to Eric's valid
> criticism. I believe you're probably wasting your time, but I'm no
> longer inclined to help.
>

If you have some helpful hints you could post whatsover because
previously you post a false clue to patch.

--
http://gamo.sdf-eu.org/
perl -E 'say "Error: ego attack."'

Keith Thompson

unread,
Aug 27, 2021, 12:55:15 PMAug 27
to
gamo <ga...@telecable.es> writes:
> El 26/8/21 a las 22:37, Keith Thompson escribió:
>> gamo <ga...@telecable.es> writes:
>>> El 26/8/21 a las 10:45, Eric Pozharski escribió:
>>>> You didn't address the main point. Can you re-invent '__DATA__'?
>>>> Sure you can. Can you workaround your re-invention? Totally. And
>>>> still. Sometimes, there're places in your Hero's Journey where you just
>>>> must keep your NIH at bay. Just read the fscking DATA, it's already
>>>> there.
>>>
>>> Pollaski, huh, get your toxicity and negativity and give it to another
>>> target. By the way, Perl is still better than... name it, and doesn't
>>> deserve pyscho-users patronizing others over 'timtowtdi'.
>> I was just about to offer a (hopefully) helpful followup, but after
>> reading this I've decided not to. You overreacted to Eric's valid
>> criticism. I believe you're probably wasting your time, but I'm no
>> longer inclined to help.
>
> If you have some helpful hints you could post whatsover because
> previously you post a false clue to patch.

False clue? What are you talking about?

gamo

unread,
Aug 27, 2021, 1:25:10 PMAug 27
to
El 27/8/21 a las 18:55, Keith Thompson escribió:
>> If you have some helpful hints you could post whatsover because
>> previously you post a false clue to patch.
> False clue? What are you talking about?

$PROGRAM_NAME
$0 Contains the name of the program being executed.

On some (but not all) operating systems assigning to $0
modifies the argument area that the "ps" program sees. On some
platforms you may have to use special "ps" options or a
different "ps" to see the changes. Modifying the $0 is
more useful as a way of indicating the current program state than it is
for hiding the program you're running.

Note that there are platform-specific limitations on the
maximum length of $0. In the most extreme case it may be limited to the
space occupied by the original $0.

In some platforms there may be arbitrary amount of
padding, for example space characters, after the modified name as shown
by "ps". In some platforms this padding may extend all the
way to the original length of the argument area, no
matter what you do (this is the case for example with Linux 2.2).

Note for BSD users: setting $0 does not completely
remove "perl" from the ps(1) output. For example, setting $0 to
"foobar" may result in "perl: foobar (perl)" (whether both the
"perl: " prefix and the " (perl)" suffix are shown
depends on your exact BSD variant and version). This is an operating
system feature, Perl cannot help it.

In multithreaded scripts Perl coordinates the threads so
that any thread may modify its copy of the $0 and the change becomes
visible to ps(1) (assuming the operating system plays
along). Note that the view of $0 the other threads have
will not change since they have their own copies of it.

If the program has been given to perl via the switches
"-e" or "-E", $0 will contain the string "-e".

On Linux as of perl v5.14.0 the legacy process name will
be set with prctl(2), in addition to altering the POSIX name via
"argv[0]" as perl has done since version 4.000. Now system
utilities that read the legacy process name such as ps,
top and killall will recognize the name you set when assigning to $0.
The string you supply will be cut off at 16 bytes, this
is a limitation imposed by Linux.

Mnemonic: same as sh and ksh.

So, open IN, '<', $0 or die $! # will no fail


--
http://gamo.sdf-eu.org/
perl -E 'say "Error: Insert system disk"'

Eric Pozharski

unread,
Aug 27, 2021, 1:33:12 PMAug 27
to
with <8735qwg...@nosuchdomain.example.com> Keith Thompson wrote:
> gamo <ga...@telecable.es> writes:
>> El 26/8/21 a las 10:45, Eric Pozharski escribió:

*SKIP*
>> Pollaski, huh, get your toxicity and negativity and give it to
>> another target. By the way, Perl is still better than... name it, and
>> doesn't deserve pyscho-users patronizing others over 'timtowtdi'.
> I was just about to offer a (hopefully) helpful followup, but after
> reading this I've decided not to. You overreacted to Eric's valid
> criticism. I believe you're probably wasting your time, but I'm no
> longer inclined to help.

This actually rises important problem, how someone can confer a point
(with goal of transmitting it)? I don't know.

Anyway, in summary, gamo is transmitting a message: (1) reading from
script itself -- abandoned; (2) inventing serialization -- abandoned;
(3) assigning to list of arrays -- abandoned. It's not a dead horse
anymore, it's a graveyard.

Eric Pozharski

unread,
Aug 27, 2021, 1:33:13 PMAug 27
to
with <877dg8h...@nosuchdomain.example.com> Keith Thompson wrote:
> gamo <ga...@telecable.es> writes:
>> El 26/8/21 a las 2:47, gamo escribió:
>>> El 26/8/21 a las 0:42, Keith Thompson escribió:

*SKIP*
>> my $full = `which $0`;
>> chomp ($full);
>> my $zero = length($full) > length($0) ? $full : $0;
>> open IN, '<', $zero or die $!;
*SKIP*
> Actually I'm not sure that's necessary. In all cases I've tried,
> Perl's $0 gives you the full path to the script, even if you invoked
> it via $PATH. (The cases I've tried are Ubuntu and Cygwin, both
> POSIX-like environments.)
>
> Bash's $0 behaves the same way. C's argv[0] (again, in the cases I've
> tried) gives you the string used to invoke the command, not
> necessarily its full path.
>
> `perldoc perlvar` says it "Contains the name of the program being
> executed" -- which leaves open the question of what "the name" means.

I suppose that mootness stems from: execve(2) to have 'filename' and
'argv[0]' (both are C-concepts) as two distinct features; and perl only
exposing 'argv[0]'

=== contents (/home/whynot/bin/Qi0XW3.pl) goes below ===
#!/usr/bin/perl

print "pwd: ", $ENV{PWD}, "\n";
print '$0: ', $0, "\n";
$0 = "BOOM!";
print '$0: ', $0, "\n"

__END__
=== contents (/home/whynot/bin/Qi0XW3.pl) gone above ===

=== contents (Qi0XW3.pl) goes below ===
pwd: /home/whynot
$0: /home/whynot/bin/Qi0XW3.pl
$0: BOOM!
=== contents (Qi0XW3.pl) gone above ===

And most importantly, ignoring 'filename' (of execve(2)) is the only
option, because it's '/usr/bin/perl' and can't be anything else.

*CUT*

Keith Thompson

unread,
Aug 27, 2021, 2:13:26 PMAug 27
to
gamo <ga...@telecable.es> writes:
> El 27/8/21 a las 18:55, Keith Thompson escribió:
>>> If you have some helpful hints you could post whatsover because
>>> previously you post a false clue to patch.
>> False clue? What are you talking about?
>
> $PROGRAM_NAME
> $0 Contains the name of the program being executed.
>
[50 lines deleted]
>
> So, open IN, '<', $0 or die $! # will no fail

There was no false clue.

I don't see anything in the documentation for $0 that implies that it
gives you the full path (most of it talks about what happens when you
modify $0). I merely pointed out that I don't see a guarantee that it
does so. I *also* pointed out that your problem can be solved more
cleanly without using $0 at all.

gamo

unread,
Aug 27, 2021, 3:02:09 PMAug 27
to
El 27/8/21 a las 20:13, Keith Thompson escribió:
> I don't see anything in the documentation for $0 that implies that it
> gives you the full path (most of it talks about what happens when you
> modify $0). I merely pointed out that I don't see a guarantee that it
> does so. I*also* pointed out that your problem can be solved more
> cleanly without using $0 at all.

Could be true, but the part

open ... or die $!;

can deal with the exceptions.

gamo

unread,
Aug 27, 2021, 5:39:48 PMAug 27
to
El 27/8/21 a las 12:30, Eric Pozharski escribió:
> Anyway, in summary, gamo is transmitting a message: (1) reading from
> script itself -- abandoned; (2) inventing serialization -- abandoned;
> (3) assigning to list of arrays -- abandoned. It's not a dead horse
> anymore, it's a graveyard.

(1) Not abandoned - is interesting how could you include multiple data
sources in one script
(2) Serializing - that's the medication you prescribed without need. If
I include plain or csv text, chances are that I do not need a module
(3) Asigning to what??? Perl does not have pure 'arrays'. It have list
of lists, and you are normally free to use as you are pleased to do


--
http://gamo.sdf-eu.org/
perl -E 'say "Preemptive error of error."'

Eric Pozharski

unread,
Aug 28, 2021, 1:33:22 PMAug 28
to
with <sgbm2u$1ob8$1...@gioia.aioe.org> gamo wrote:
> El 27/8/21 a las 12:30, Eric Pozharski escribió:

>> Anyway, in summary, gamo is transmitting a message: (1) reading from
>> script itself -- abandoned; (2) inventing serialization --
>> abandoned; (3) assigning to list of arrays -- abandoned. It's not a
>> dead horse anymore, it's a graveyard.
>
> (1) Not abandoned - is interesting how could you include multiple data
> sources in one script

I don't see any reading here <sg6vvk$19pn$1...@gioia.aioe.org>. Here-docs
aren't readings, they are syntax. Also, see below.

> (2) Serializing - that's the medication you prescribed without need.
> If I include plain or csv text, chances are that I do not need a
> module

CSV is serialization; strictly speaking, for subset of arrays of hashes
of scalars. My failed attempt to introduce you to YAML was a mistake --
at that moment, I didn't know that you're attached so much to your
home-brewed serialization. And that attachement is OK, it's
manifestation of cost of opportunity matrix. Your cost of opportunity
matrix has different weights in it, hence your affront. I didn't know
that. Also, see below.

> (3) Asigning to what??? Perl does not have pure 'arrays'. It have list
> of lists, and you are normally free to use as you are pleased to do

This is array (per 'perldoc perldata')

@foo

This is list (per 'perldoc perldata')

( @foo )

This is list of arrays (per 'perldoc perldata')

( @foo, @bar, @quux )

Mine 'list of arrays' is a shorthand, maybe wrong (it's misleading;
can't think of better term at the moment; might take years to come up
with proper term).

Wrong. This works (per design)

@foo = @bar

This works (by accident)

( @foo ) = ( @bar )

This doesn't work (unless it's for initialization, then it's fine)

( @foo, @bar ) = ( @baz, @quux )

This doesn't work *and* doesn't compile (per 'use warnings')

( @foo, @bar ) = @baz, @quux

No, nobody is "free to use as you are pleased". Syntax won't let it.

One more thing that nobody is free to use is terminology. Anybody
either sticks to terminology or invents their own. Anybody is free to
invent terminology. However, unless such terminology (with clear
definitions) is provided *upfront* such individuals, sooner or later,
will be phased out into oblivion (per cost of opportunity matrix,
nothing sinister).

gamo

unread,
Aug 28, 2021, 2:36:51 PMAug 28
to
El 28/8/21 a las 17:22, Eric Pozharski escribió:
> with <sgbm2u$1ob8$1...@gioia.aioe.org> gamo wrote:
>> El 27/8/21 a las 12:30, Eric Pozharski escribió:
>
>>> Anyway, in summary, gamo is transmitting a message: (1) reading from
>>> script itself -- abandoned; (2) inventing serialization --
>>> abandoned; (3) assigning to list of arrays -- abandoned. It's not a
>>> dead horse anymore, it's a graveyard.
>>
>> (1) Not abandoned - is interesting how could you include multiple data
>> sources in one script
>
> I don't see any reading here <sg6vvk$19pn$1...@gioia.aioe.org>. Here-docs
> aren't readings, they are syntax. Also, see below.
>

Copy & paste:

> Maybe. Look at the latest version to say if it's 'workable' or not.
>
> #!/usr/bin/perl -w
>
> use strict;
> # no strict 'refs';
>
> # my @names = "A".."Z"; # there are single letters that can't
be used with strict
> # my $files = scalar(@names);
>
> my $data = 0;
>
> my @array;
>
> open IN, '<', $0 or die $!;
This is working code, P., sorry to notify you that.

*CUT*

--
http://gamo.sdf-eu.org/
perl -E 'say "Error: Repetition."'

Eric Pozharski

unread,
Aug 29, 2021, 1:33:12 PMAug 29
to
with <sgdvnq$t22$1...@gioia.aioe.org> gamo wrote:
> El 28/8/21 a las 17:22, Eric Pozharski escribió:
>> with <sgbm2u$1ob8$1...@gioia.aioe.org> gamo wrote:
>>> El 27/8/21 a las 12:30, Eric Pozharski escribió:

*SKIP*
> Copy & paste:

I hope everyone is happy now. Good to know.

*CUT*

gamo

unread,
Aug 29, 2021, 2:40:11 PMAug 29
to
El 29/8/21 a las 16:51, Eric Pozharski escribió:
> with <sgdvnq$t22$1...@gioia.aioe.org> gamo wrote:
>> El 28/8/21 a las 17:22, Eric Pozharski escribió:
>>> with <sgbm2u$1ob8$1...@gioia.aioe.org> gamo wrote:
>>>> El 27/8/21 a las 12:30, Eric Pozharski escribió:
>
> *SKIP*
>> Copy & paste:
>
> I hope everyone is happy now. Good to know.
>
> *CUT*
>

Put your sacarsm after appropiate comments symbol.

# HA!

*REDO*

*UNDO*

*DISCARD*

--
http://gamo.sdf-eu.org/
perl -E 'say "Graham Bell discovered the phone. It had 3 lost calls."'

George Bouras

unread,
Sep 1, 2021, 4:29:18 AMSep 1
to
Στις 20/8/2021 3:23 μ.μ., ο/η gamo έγραψε:
> while (<DATA1>){
> }
> while (<DATA2>){
> }
>
> say "blah";
>
> exit 1;
>
> __DATA1__
> 1, 2
> 3, 4
> __DATA2__
> 2, 4
> 6, 8
> __END__




open DATA1, '<', \<<foo;
1, 2
3, 4
foo

open DATA2, '<', \<<foo;
2, 4
6, 8
foo

while (<DATA1>) { print }
while (<DATA2>) { print }

gamo

unread,
Sep 1, 2021, 5:11:31 AMSep 1
to
El 1/9/21 a las 10:29, George Bouras escribió:
> open DATA1, '<', \<<foo;
> 1, 2
> 3, 4
> foo
>
> open DATA2, '<', \<<foo;
> 2, 4
> 6, 8
> foo
>
> while (<DATA1>) { print }
> while (<DATA2>) { print }

Hey George, chapeau!

You are winner of the context.
I hope all of you have a good september.

Thank you very much.


--
http://gamo.sdf-eu.org/
perl -E 'say "Error: Batteries low"'
Reply all
Reply to author
Forward
0 new messages