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