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
El 20/8/21 a las 14:23, gamo escribió:
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.
while (<IN>){
if (/__DATA(\d+)__/) { $data = $1; }
if (/__END__/) { $data = 0; }
push @{ $array[$data] }, $_ if $data > 0;
}
But, you probably already know that. May I introduce you
to fine, already existing, and widely supported world of YAML?
still better than Terrafom's progamming language disguised as data structure
In comp.lang.perl.misc, Eric Pozharski <whynot@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.
Not to mention "Oh yeah, JSON is is a valid YAML format, too."
still better than Terrafom's progamming language disguised as data
structure
Hi there!
El 23/8/21 a las 20:36, Eli the Bearded escribió:
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?
El 24/8/21 a las 16:06, Eric Pozharski escribió:
Doubts start to creep in. Here you're still pushing '__DATA000__'Nope. It's only a concept. But since I could code __DATA1__ and insert
onto your arrays. Are you really running your code?
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.
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.
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 arraysMaybe. Look at the latest version to say if it's 'workable' or not.
then.
#!/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 $!;
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.
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;
perl -E 'say "Guess what?"'
El 26/8/21 a las 2:47, gamo escribió:
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;
my $full = `which $0`;
chomp ($full);
my $zero = length($full) > length($0) ? $full : $0;
open IN, '<', $zero or die $!;
Hope this works.
You
wouldn't have to worry about the behavior of $0. Why is <DATA> not
suitable for your purpose?
gamo <gamo@telecable.es> writes:
El 25/8/21 a las 12:34, Eric Pozharski escribió:
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__.
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.
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'.
gamo <gamo@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.
El 26/8/21 a las 22:37, Keith Thompson escribió:
gamo <gamo@telecable.es> writes:
El 26/8/21 a las 10:45, Eric Pozharski escribió:I was just about to offer a (hopefully) helpful followup, but after
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'.
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.
gamo <gamo@telecable.es> writes:
El 26/8/21 a las 10:45, Eric Pozharski escribió:
Pollaski, huh, get your toxicity and negativity and give it toI was just about to offer a (hopefully) helpful followup, but after
another target. By the way, Perl is still better than... name it, and
doesn't deserve pyscho-users patronizing others over 'timtowtdi'.
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.
El 27/8/21 a las 18:55, Keith Thompson escribió:
If you have some helpful hints you could post whatsover becauseFalse clue? What are you talking about?
previously you post a false clue to patch.
$PROGRAM_NAME
$0 Contains the name of the program being executed.
So, open IN, '<', $0 or die $! # will no fail
If you have some helpful hints you could post whatsover becauseFalse clue? What are you talking about?
previously you post a false clue to patch.
gamo <gamo@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 $!;
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 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.
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.
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
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.
Maybe. Look at the latest version to say if it's 'workable' or not.be used with strict
#!/usr/bin/perl -w
use strict;
# no strict 'refs';
# my @names = "A".."Z"; # there are single letters that can't
# 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__
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ó:
Copy & paste:
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*
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 }
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 286 |
Nodes: | 16 (2 / 14) |
Uptime: | 89:32:00 |
Calls: | 6,496 |
Calls today: | 7 |
Files: | 12,100 |
Messages: | 5,277,448 |