Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: pseudocode for getting data from table

by Tux (Canon)
on Sep 22, 2020 at 07:09 UTC ( #11122062=note: print w/replies, xml ) Need Help??


in reply to Re^2: pseudocode for getting data from table
in thread pseudocode for getting data from table

That is under-specified. What is the table layout? Spaces only or tabs? With TAB's, have a loog at Text::CSV and it's faster parent Text::CSV_XS. If spaces only, you have a problem, as the first line is not aligned with the rest. If it were, pack/unpack would most likely be of help:

# Example using split on multiple spaces open my $fh, "<", "INPUT"; while (<$fh>) { $. < 100 and next; chomp; my ($typ, $gid, $org, $lvl) = split m/\s\s+/ => $_; say "$. $gid, $lvl"; } close $fh; # Example with TAB's use Text::CSV_XS; open my $fh, "<", "INPUT"; my $csv = Text::CSV_XS->new ({ binary => 1, sep_char => "\t", auto_dia +g => 1 }); while (my $line = $csv->getline ($fh)) { $csv->record_number < 100 and next; my ($typ, $gid, $org, $lvl) = @{$line}; say "$. $gid, $lvl"; } close $fh; # Example with unpack (I manually aligned the header line) open my $fh, "<", "INPUT"; while (<$fh>) { $. < 100 and next; chomp; my ($typ, $gid, $org, $lvl) = unpack "A25 A10 A26 A*" => $_; say "$. $gid, $lvl"; } cloase $fh;

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^4: pseudocode for getting data from table
by shabird (Sexton) on Sep 22, 2020 at 09:25 UTC

    You have wrote an implementation of it but i asked to check my pseudocode if it is correct or not?

      (pseudo)code cannot be validated if the (input)requirements are not clear.

      So, sorry if I took the fun part out of your assignment, but this is how I try to make sense of pseudo-code.

      What pseudo-code also doesn't clearly define is the output-format and validation of input. Also things to think about (also in pseudo-code).

      As I personally "do" a lot of perl, I think perl, so my pseudo-code *is* perl. Be it with typoes and syntax errors, but perl (when using strict and warnings) will point me at those for me to fix.


      Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11122062]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-04-16 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?