Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thank you McA. Sorry for the error. I was writing the program with variables in Spanish and decided to change to English before posting here. I ran a search & replace on that variable and replaced without $. All edi_file should be $edi_file.

#!/usr/bin/perl use strict; use warnings; use File::HomeDir; use List::Util 'first'; use List::MoreUtils 'first_index'; use Text::CSV; my @po = &open_po; #my @po_no_headings = &erase_headings(@po); #my @po_separated = &make_product_store_quantity(@po_no_headings); #print "@po_separated\n"; my ($li_stores_ref, $ff_stores_ref) = &separate_stores; my @liv_stores = @$li_stores_ref; my @ffr_stores = @$ff_stores_ref; print "Li stores: @liv_stores\n"; print "FF Stores: @ffr_stores\n"; # **************************************** # 1) open .EDI file # 2) split into lines through "~" line separator # 3) Place .EDI file contents into @po_array sub open_po { my ($edi_file, $po_data, @po_array); $edi_file = File::HomeDir->my_home . "/example/po//example.EDI" or d +ie ".EDI file not found\n"; open ($po_data, '<', $edi_file) or die "Could not open the file 'edi +_file' $!\n"; undef $/; @po_array = split (/\~/, <$po_data>); close $po_data; return @po_array; } # **************************************** # Erase all information from purchase order before first PO1 line sub erase_headings { my ($delete_point); $delete_point = (first_index {/PO1/} @_) - 1; # Find first PO1 line # Shift array up to first PO1 line for (0..$delete_point) { shift @_; } @_; } # **************************************** # Return array with product, store, quantity # (i.e. THSB01 00021 3 00043 1 THSB02...etc.) sub make_product_store_quantity { my (@line, @product_stores, $product, $product_index); while(scalar (@_) !=0) { @line = split (/\*/, $_[0]); # Split line into fields # Find product code (i.e. THSB01) and shift array twice if ($line[0] eq "PO1") { $product_index = (first_index {/ST/} @line) + 1; $product = $line[$product_index]; shift; shift; } # Find stores & quantity for each store. # Write product code followed by stores & quantity to array @product_s +tores if ($line[0] eq "SDQ") { shift (@line); shift (@line); shift (@line); unshift (@line, $product); push (@product_stores, @line); shift; # Exit when PO line starts with CTT, meaning end of PO1 details } elsif ($line[0] eq "CTT") { undef (@_); } } @product_stores; } # **************************************** # 1) Open and read stores.csv # 2) Place all "li" type store numbers in @li_store array # 3) Place all "ff" type store numbers in @ff_store array # 4) Return array references sub separate_stores { my (@li_stores, @ff_stores); my $stores_file = File::HomeDir->my_home . "/example/data/example.cs +v"; open my $fh, "<", $stores_file or die "$stores_file: $!"; my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, }); my $count_li = 0; my $count_ff = 0; $csv ->getline ($fh); while (my $row = $csv->getline ($fh)) { if ($row->[1] eq "li") { $li_stores[$count_li] = $row->[0]; $count_li ++; } else { $ff_stores[$count_ff] = $row->[0]; $count_ff ++; } } close $fh; return (\@li_stores, \@ff_stores); }

In reply to Re^2: Cannot work on second file after reading first file. by 1straw
in thread Cannot work on second file after reading first file. by 1straw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-26 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found