Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Inserting a header into outfile

by jeretjordan (Initiate)
on Mar 14, 2017 at 15:19 UTC ( [id://1184558]=perlquestion: print w/replies, xml ) Need Help??

jeretjordan has asked for the wisdom of the Perl Monks concerning the following question:

This my very first week using Perl. My question is how and where would I add in a list of headers that I need to show in my out file? This is the list of headers I want outputted ETXLinkID,TranscomLinkID,TranscomLen,TranscomLenFrac,EtxLenFrac,EtxLen

#!perl use ; $, = ' '; # set output field separator $\ = "\n"; # set output record separator $TOLERANCE = 0.000001; ### ### ETX Link ID read fields ### ### Field Order: 0 LINK_ID ** WANTED ### Field Order: 1 Link_Name ### Field Order: 2 Native_Link_ID ### Field Order: 3 Owner_Name ### Field Order: 4 Description ### Field Order: 5 Link_Type ### Field Order: 6 Direction ** WANTED ### Field Order: 7 Begin_State ### Field Order: 8 End_State ### Field Order: 9 Begin_Facility ** WANTED ### Field Order: 10 End_Facility ### Field Order: 11 Begin_Point_Name ### Field Order: 12 End_Point_Name ### Field Order: 13 Begin_Point_ID ### Field Order: 14 End_Point_ID ### Field Order: 15 BEGIN_EXT_NAME ### Field Order: 16 END_EXT_NAME ### Field Order: 17 BEGIN_LAT ** WANTED ### Field Order: 18 BEGIN_LON ** WANTED ### Field Order: 19 END_LAT ** WANTED ### Field Order: 20 END_LON ** WANTED ### Field Order: 21 Status ### Field Order: 22 LastUpdated ### Field Order: 23 LENGTH Meters ### Transcom Link ID read fields ### ### Field Order: 0 TranscomLinkID ** WANTED ### Field Order: 1 LinkName ### Field Order: 2 TranscomRoadName ** WANTED ### Field Order: 3 Direction ** WANTED ### Field Order: 4 StartLat ** WANTED ### Field Order: 5 StartLon ** WANTED ### Field Order: 6 EndLat ** WANTED ### Field Order: 7 EndLon ** WANTED ### Field Order: 8 Length ** WANTED Meters #### Lookup Table #### ### Field Order: 0 SourceFacilityName ### Field Order: 1 LocalFacilityName with direction #### $icnt = 0; $fname = $ARGV[0]; ##$fname = 'Transcom_XREF.txt'; ### ### LookUP DATA Read for Cross Reference ### my $csv = Text::CSV_XS->new ({ binary => 1 }) or die "Cannot use CSV: ".Text::CSV_XS->error_diag (); open my $fh, "<:encoding(utf8)", $fname or die "cannot Open $fname +: $!"; line: while (my $row = $csv->getline ($fh)) { if ($icnt == 0) { # Skip Header Record $icnt++; next; } @Fld = @$row; $ky = $Fld[1]; $LookUp{$ky} = $Fld[0]; # Save Translation table from Transcom + RoadName field to ETX facility name $Assgn{$Fld[0]} = $ky; # Save Assignment of Transcom value to + KEY ## print "LOOKUP..ky..$ky..LookUp..$LookUp{$ky}..."; ## print "LOOKUP..ky..$ky..Assgn{$Fld[0]}..$Assgn{$Fld[0]}..."; + next line; } # **End of line: Loop over all records in file close($fh); ### $icnt = 0; ##$fname = $ARGV[0]; $fname = $ARGV[1]; ### ### TRANSCOM DATA Read ### my $csv = Text::CSV_XS->new ({ binary => 1 }) or die "Cannot use CSV: ".Text::CSV_XS->error_diag (); open my $fh, "<:encoding(utf8)", $fname or die "cannot Open $fname : +$!"; line: while (my $row = $csv->getline ($fh)) { if ($icnt == 0) { # Skip Header Record $icnt++; next; } @Fld = @$row; $bt = $Fld[4]; ## StartLat $et = $Fld[6]; ## EndLat $bl = $Fld[5]; ## StartLong $el = $Fld[7]; ## EndLong ##print "TXDOT..BEGIN...fld0..$Fld[0]..f2..$Fld[2]....f7..$Fld[7]..bt. +.$bt..et..$et..bl..$bl..el..$el..$#Fld.."; $dy = ($et - $bt); $dx = ($el - $bl); $dist = sqrt($dx*$dx +$dy*$dy); if( $dist < $TOLERANCE ) { # Check to make sure segment is v +alid next line; } $vx = $dx/$dist; # Normalize the Basis Vector $vy = $dy/$dist; ##print "TXDOT..B4..ckkey...fld0..$Fld[0]..f2..$Fld[2]....f7..$Fld[7]. +.f1..$Fld[1]..f3..$Fld[3]...#fld..$#Fld.."; $key = $Assgn{$Fld[0]}; ##print "TRANSCOM..key...$key...TRANSCOM Link..$Fld[0].."; ## } ## if( $key eq "-1 : -1" ) { ## print "TXDOT..NO MATCH..$key..ckkey..$ckkey..fld0..$Fld[0]..f2 +..$Fld[2]..f7..$Fld[7]..f1..$Fld[1]..#fld..$#Fld.."; ## print "-1,$Fld[0],-1"; ## } $id{$key}++; $np = $id{$key}-1; $lnkID{$key, $np} = $Fld[0]; # Store Transcom LinkID $blat{$key, $np} = $bt; # Store Beginning Latitude $blng{$key, $np} = $bl; # Store Beginning Longtitude $elat{$key, $np} = $et; # Store Ending Latitude $elng{$key, $np} = $el; # Store Ending Longitude $lngth{$key, $np} = $Fld[8]; # Store length $vx0{$key, $np} = $vx+0.0; $vy0{$key, $np} = $vy+0.0; $tdst{$key, $np} = $dist+0.0; next line; } # **End of line: Loop over all records in file close($fh); ### ### ETX Link ID Read File (in Smartnet data format) ### $icnt = 0; ##$fname = $ARGV[1]; $fname = $ARGV[2]; my $csv = Text::CSV_XS->new ({ binary => 1 }) or die "Cannot use CSV: ".Text::CSV_XS->error_diag (); open my $fh, "<:encoding(utf8)", $fname or die "cannot Open $fname : +$!"; line: while (my $row = $csv->getline ($fh)) { if ($icnt == 0) { $icnt++; next; } @Fld = @$row; $ddr = $Fld[6]; # Get direction ONLY from field $ddr =~ m/(Frontage Rd)/; $fr = ""; if( $1 ne "" ) { $fr = "FR"; } if( index($ddr,"3") >= 0 ) { $dr = "EB"; } elsif( index($ddr,"4") >= 0 ) { $dr = "WB"; } elsif( index($ddr,"1") >= 0 ) { $dr = "NB"; } elsif( index($ddr,"2") >= 0 ) { $dr = "SB"; } else { $dr = ""; } ##print "ETX dr...$dr..ETXlnkid..$Fld[0]..."; #JAW $ns = (@tok = split(/ /, $ky, -1)); ## $ns = (@tok = split(/,/, $i, -1)); #JAW $nm = $tok[0]; $nm = $Fld[9]; # Get BeginField ONLY. t +his is the link facility name #JAW if( index($ky,"STHY 5 ") >= 0 ) { #JAW $nm = "K Avenue"; #JAW } #JAW else { #JAW $nm .= $tok[1]; #JAW } #JAW $nm .= $fr; $nmtch = $dr . $nm; # direction and facility + name forms unique key #JAW $nmtch =~ s/ //g; # do not remove spaces $key = $nmtch; # save Roadway ADJUSTED (Begin_Facility) ## $key = $Fld[9]; # save Roadway (Begin_Facility) ## if ( exists $LookUp{$Fld[9]} ) { # CHECK LOOKUP KEY : TxDOT ke +y field with SmartNET Begin Facility ## $key = $LookUp{$Fld[9]}; # save Roadway Key ## } ##print "ETX..key...$key..ETXlnkid..$Fld[0]..."; $sid{$key}++; $np = $sid{$key}-1; $slnkID{$key, $np} = $Fld[0]; # Store ETX LINK_ID $sblat{$key, $np} = $Fld[17]; # Store BEGIN_LAT $sblng{$key, $np} = $Fld[18]; # Store BEGIN_LON $selat{$key, $np} = $Fld[19]; # Store END_LAT $selng{$key, $np} = $Fld[20]; # Store END_LON $slnklen{$key, $np} = $Fld[23]; # Store ETX link length $dir{$key, $np} = $tmp; # Store Psuedo-Direction from ETX next line; } # **End of line: Loop over all records in file close($fh); ########### ########### ## Main Program - Calculate Segments over Links ########### ########### ####### ####### ####### Process the data ####### ####### foreach $i (keys %id) { # $i is the ETXFacilit +y Name ##print "The i..$i..this is ETXFacility Name"; ## $nv = (@tok = split(/:/, $i, -1)); # Split Roadway : Directi +on for TXDOT foreach $j (keys %sid) { # $j is the direction + + ETXFacility Name ##print "The j..$j..this is direction + ETXFacility Name"; ## $iv = ( $i eq $j); ##print "MATCHING..CHK..i..$i..j..$j.....lnkID.$lnkID{$i,0}..slnkID... +$slnkID{$j,0}..."; if( ($il=index($j,$i)) >= 0 ) { # if( $i eq $j ) { # check if Roadway Name +is within ETX Begin_Facility ##print "MATCHING..CHK..i..$i..j..$j.....lnkID.$lnkID{$i,0}..slnkID... +$slnkID{$j,0}..."; $nb = $id{$i}; # number of Transcom lin +ks under this LocalFacility name ##print "nb..$nb"; for($k=0; $k<$nb; $k++) { # Loop Transcom segments ( +BASIS) $ns = $sid{$j}; # number of ETX links f +or the direction + Local Facility Name ##print "ns..$ns"; for($l=0; $l<$ns; $l++) { # Loop ETX segments $ky = $slnkID{$j, $l} . ":" . $lnkID{$i, $k} . ":" . $lngth{ +$i, $k} . ":" . $slnklen{$j, $l}; # Build Key for holding results ET +XLinkID:TranscomLinkID:TranscomLinkLength $ksy = $slnkID{$j, $l}; # Save ETX Ke +y for holding results ETXLinkID ##print "ky..$ky.....ksy...$ksy"; ## ## First check BEGINNING point within segment ## $dy = ($sblat{$j, $l} - $blat{$i, $k}); $dx = ($sblng{$j, $l} - $blng{$i, $k}); $dist = sqrt($dx*$dx +$dy*$dy); if( $dist < $TOLERANCE ) { last; } $vx1 = $dx/$tdst{$i, $k}; # Normalize the 1st Vector to +check RELATIVE to DISTANCE OF BASIS $vy1 = $dy/$tdst{$i, $k}; ##print "j..$j..l..$l..k..$k"; ##print "check BEGINNING point within segment"; ##print "sblat{j, l}..$sblat{$j, $l}..sblng{j, l}..$sblng{$j, $l}..bla +t{i, k}..$blat{$i, $k}..blng{i, k}..$blng{$i, $k}..tdst{i, k}..$tdst{ +$i, $k}"; ##print "for dotp1..dy..$dy..dx..$dx..dist..$dist..vx1..$vx1..vy1..$vy +1..vx0..$vx0{$i, $k}..vy0..$vy0{$i, $k}"; $dotp1 = $vx1*$vx0{$i, $k} + $vy1*$vy0{$i, $k}; # Find di +stance along vector for Beginning point ##print "dotp1...$dotp1"; ## ## Now check ENDING point within segment ## $dy = ($selat{$j, $l} - $blat{$i, $k}); $dx = ($selng{$j, $l} - $blng{$i, $k}); $dist = sqrt($dx*$dx +$dy*$dy); if( $dist < $TOLERANCE ) { last; } $vx2 = $dx/$tdst{$i, $k}; # Normalize the 2nd Vector to +check RELATIVE to DISTANCE OF BASIS $vy2 = $dy/$tdst{$i, $k}; ##print "check ENDING point within segment"; ##print "selat{j, l}..$selat{$j, $l}..selng{j, l}..$selng{$j, $l}..bla +t{i, k}..$blat{$i, $k}..blng{i, k}..$blng{$i, $k}"; ##print "for dotp2..dy..$dy..dx..$dx..dist..$dist..vx2..$vx2..vy2..$vy +2"; $dotp2 = $vx2*$vx0{$i, $k} + $vy2*$vy0{$i, $k}; # Find di +stance along vector for Ending point ##print "dotp2...$dotp2"; ## ## Now check DOT PRODUCTS to find where along the basis vector line ## if( $dotp1 > 1.0 && $dotp2 > 1.0 ) { # Both point +s beyond END next; } elsif( $dotp1 < 0.0 && $dotp2 < 0.0 ) { # Both point +s before BEGIN next; } elsif( $dotp2 < $dotp1 ) { # Wrong Direction for Vecto +r - SWITCH DOT VALUES **** $dtmp = $dotp2; $dotp2 = $dotp1; $dotp1 = $dtmp; } ##print "dotp1...$dotp1..dotp2...$dotp2"; if( $dotp1 >= 0.0 ) { if( $dotp2 <= 1.0 ) { # Entire Segment is Completely i +nside $snC2Clen{$ky} = ($dotp2 - $dotp1); } elsif( $dotp2 > 1.0 ) { # Segment is Beyond Endpoint - + Truncate $snC2Clen{$ky} = (1.0 - $dotp1); } else { # Segment NOT FOUND in Basis V +ector $snC2Clen{$ky} = -1.0; } } elsif( $dotp1 <= 0.0 ) { if( $dotp2 >= 1.0 ) { # Segment Covers Entire Basis +Vector $snC2Clen{$ky} = 1.0; } elsif( $dotp2 > 0.0 ) { # Segment Starts before Basis +Vector (dotp2 - 0.0) $snC2Clen{$ky} = $dotp2; } else { # Segment NOT FOUND in Basis V +ector $snC2Clen{$ky} = -1.0; } } ##print "snC2Clen{ky}...$snC2Clen{$ky}"; ## ## NOW FIND Percent of ETX LinkID that is being used - ## ## ## Find NEW ETX Basis Vector ## $dy = ($selat{$j, $l} - $sblat{$j, $l}); $dx = ($selng{$j, $l} - $sblng{$j, $l}); $sdist = sqrt($dx*$dx +$dy*$dy); if( $sdist < $TOLERANCE ) { $sdist = 1.0 } $vxS = $dx/$sdist; # Normalize the SmartNET Vector $vyS = $dy/$sdist; ## ## Now find BEGINNING Transcom Link Segment relative to ETX Basis Vect +or ## $dy = ($blat{$i, $k} - $sblat{$j, $l}); $dx = ($blng{$i, $k} - $sblng{$j, $l}); $dist = sqrt($dx*$dx +$dy*$dy); if( $dist < $TOLERANCE ) { $dist = 1.0 } $vx1 = $dx/$sdist; # Normalize the 1st Vector to check R +ELATIVE to SmartNET BASIS $vy1 = $dy/$sdist; $dotp1 = $vx1*$vxS + $vy1*$vyS; # Find distance along vec +tor for Beginning point ## ## Now find ENDING Transcom Link segment relative to ETX Basis Vector ## $dy = ($elat{$i, $k} - $sblat{$j, $l}); $dx = ($elng{$i, $k} - $sblng{$j, $l}); $dist = sqrt($dx*$dx +$dy*$dy); if( $dist < $TOLERANCE ) { $dist = 1.0 } $vx2 = $dx/$sdist; # Normalize the 2nd Vector to check R +ELATIVE to DISTANCE OF BASIS $vy2 = $dy/$sdist; $dotp2 = $vx2*$vxS + $vy2*$vyS; # Find distance along vec +tor for Ending point ## ## Now check DOT PRODUCTS to find where along the basis vector line ## if( $dotp2 < $dotp1 ) { # Wrong Direction for Vector - + SWITCH DOT VALUES **** $dtmp = $dotp2; $dotp2 = $dotp1; $dotp1 = $dtmp; } if( $dotp1 >= 0.0 ) { if( $dotp2 <= 1.0 ) { # Entire Segment is Completely i +nside $ln = ($dotp2 - $dotp1); if( $ln > 0 ) { $snPLen{$ky} += ($dotp2 - $dotp1); $snLen{$ksy} += ($dotp2 - $dotp1); } } elsif( $dotp2 > 1.0 ) { # Segment is Beyond Endpoint - + Truncate $ln = (1.0 - $dotp1); if( $ln > 0 ) { $snPLen{$ky} += (1.0 - $dotp1); $snLen{$ksy} += (1.0 - $dotp1); } } else { # Segment NOT FOUND in Basis V +ector $snPLen{$ky} = -1.0; $snLen{$ksy} = -1.0; } } elsif( $dotp1 <= 0.0 ) { if( $dotp2 >= 1.0 ) { # Segment Covers Entire Basis +Vector $snPLen{$ky} = 1.0; $snLen{$ksy} = 1.0; } elsif( $dotp2 > 0.0 ) { # Segment Starts before Basis +Vector (dotp2 - 0.0) $ln = $dotp2; if( $ln > 0 ) { $snPLen{$ky} += $dotp2; $snLen{$ksy} += $dotp2; } } else { # Segment NOT FOUND in Basis V +ector $ln = $dotp2; if( $ln > 0 ) { $snPLen{$ky} += $dotp2; $snLen{$ksy} += $dotp2; } ## $snLen{$ksy} = -2.0; } } } # End of L loop } # End of K loop } # End of tok[0] Condition (Same Roadway) } # End of J loop (Roadway) } # End of I loop (Roadway:Direction) foreach $is (sort keys %snC2Clen) { $nv = (@tok = split(/:/, $is, -1)); # Split SnLinkID : TxLINKI +D if( $snPLen{$is} > 0 ) { ## printf "%-s,%-s,%.5lf,%.5lf,%.5lf\n", $tok[0], $tok[1], $snC2Cle +n{$is}, $snPLen{$is}, $snLen{$tok[0]}; printf "%-s,%-s,%.5lf,%.5lf,%.5lf,%.5lf\n", $tok[0], $tok[1], $t +ok[2], $snC2Clen{$is}*$tok[2], $snPLen{$is}, $tok[3]; } ## printf "%-s,%-s,%.5lf\n", $tok[0], $tok[1], $snC2Clen{$is}; ## printf "%-s,%-s,%.5lf\n", $is, $snLen{$is}; } exit;

Replies are listed 'Best First'.
Re: Inserting a header into outfile
by kennethk (Abbot) on Mar 14, 2017 at 17:01 UTC
    Please read How do I post a question effectively?. Please be sure when you post that the code runs, and provide expected output from provided inputs, all wrapped in <code> tags. In this scenario, that dangling use  ; at the top of the file is a syntax error and is a red flag that you didn't test what you posted.

    What are you using as learning material? Try Learn Perl in 2 hours 30 minutes or http://learn.perl.org. I note that you do not use strict or warnings. It's understandable that an old script might not have these, but any new code should use them. See Use strict warnings and diagnostics or die.

    The easiest solution for your spec would be to insert

    print "ETXLinkID,TranscomLinkID,TranscomLen,TranscomLenFrac,EtxLenFrac +,EtxLen\n";
    before that last foreach loop. Is there subtlety in the challenge I am missing?

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      It was really that simple I added that print statement and I got my result. Thanks for the help! I will be using the learning materials that you linked moving forward as I continue to learn.

        Dealing with legacy Perl can be a real challenge, and is a hard thing to cut your teeth on. Glad to have been helpful.

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      I'm guessing that the use ; was something like use CompanyNameStuff; that pulls in Text::CSV_XS and ghod knows what else, but it got anonymized. The OP is too new to Perl to know what to replace it with.

      Strict and warnings should be considered mandatory in any new code. Don't try to add them to old code unless you know what you are doing, because you will get a million error messages and you will freak out and say "I'm never using strict and warnings again," and you mustn't say that!

Re: Inserting a header into outfile -- a long one
by Discipulus (Canon) on Mar 14, 2017 at 21:18 UTC
    hello jeretjordan and welcome to the monastery and to wonderful world of Perl!

    We are here in the aim to help you, if this is possible. AnonymousMonk in his first replay is almost right in every point; I think you too agree.

    You have probably done a big work to end up with this 400+ lines of code. Or you have received this code from an ancient hard disk IDE and you were tasked to modify it to add headers. No problem! If you are here to learn coding good Perl, at PerlMonks you'll find very good mentors.

    If this is your code it is better to rethink the whole flow of the program. More on this later.

    If you just need to modify it, is nastier: you must fully understand all the actual program structure and all possible bogus parts (and it seems full of them!) to spot where and how to do the modification: the e) point of the above mentioned Anoymous's post fit well enought.

    If this is your code your are learning from very old codebases. Modern Perl is a lot more clean and concise and powerful and safer: absence of use strict; use warnings is guilty for the fact that they constrain you into safer lanes. An example? your program is full of scope errors. my is a duty when you use strict; but prevent you to declare many times the same var in the same scope (see your my $csv .. ).

    You must learn from better and more idiomatic Perl: PerlMonks is a good place, full of good code by wise monks (be carefullwith mine anyway ;=). To read the free ModernPerl book is a must (it has a good chapter about the scope of variables).

    Applied to your code a good sense review can spot many incorrect behaviours: when you cut & past code inside your own program, you loose. You MUST reuse code but abstracting it in subroutines. You have many times my $csv = Text::CSV_XS->new... open my $fh,...  while (my $row.... all this part is a good candidate for a sub. You can answer that each file need a different processing: the idiomatic dispatch table can become handy: a process_file sub take care of opening the file and other things then pass the filehadle by reference to different specialized sub to handle different file content. It is just an example.

    Choose meninigfull names for your vars, avoid label like line: while.. , declare variable when you need them and in the correct scope, use strict; use warnings and also remeber to use strict; use warnings , abstract as much as possible, think about your data and datastructure well and early, discover right module to use and exploit them as much as possible, borrow from expert coders..

    A possible approch must be similar to the following pseudocode:

    # pseodocode !!! use strict; use warnings; use Text::CSV_XS; # declare early used vars and others my $TOLERANCE = 0.000001; # you can also use constants in Perl.. my %final_datastructure; #verify @ARGV filling @files my @files .. # define a lookup table for different files my %lookup_table{ type_a => \&proc_file_a, type_b => \&proc_file_b, ... } foreach my $file (@files){ # maybe check readbility? or construct the full path.. process_file ($file); } # output the data out_data(\%final_datastructure); # the general sub sub process_file{ my $fname = shift; my $icnt = 0; open my $fh, "<:encoding(utf8)", $fname or die "cannot Open $fname : + $!"; # pass the filehandle to specialized subroutines if ($fname eq 'type_a.csv'){ # pass the filehandle by reference proc_file_a(\$fh); } } # the specialized sub sub proc_file_a{ my $fh = shift; my $csv = Text::CSV_XS->new ({ binary => 1 }) or die "Cannot use CSV: ".Text::CSV_XS->error_diag (); while (my $row = $csv->getline ($fh)){ # fill in the destination datastructure.. ... # sub to output the data sub out_data{ ...

    HtH

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Inserting a header into outfile
by Anonymous Monk on Mar 14, 2017 at 16:54 UTC
    a) Welcome to Perl, and welcome to the monastery.
    b) The monks aren't here to do your work for you. Don't just drop a ton of code on us and expect us to make it work.
    c) Not all Perl programs are this nasty. That's how we wrote them 30 years ago. (Almost! Perl is 30 in December.)
    d) ETXLinkID,TranscomLinkID,TranscomLen,TranscomLenFrac,EtxLenFrac,EtxLen seems to be what the program outputs right now, correct? So you don't need to calculate any new results, you just need to add a header line to the output?
    e) All the output appears to happen in the final foreach loop. If you need to print a header before the other output, print it right before that.
Re: Inserting a header into outfile
by jeretjordan (Initiate) on Mar 14, 2017 at 17:05 UTC
    < Sorry! I thought that showing the code would be beneficiary to whoever was viewing. I didn't mean to break any guidelines. I was just looking for some general directions as I am just crawling through the dark with this right now. Thanks for the help! />

      Hello jeretjordan and welcome to the Monastery.

      I didn't mean to break any guidelines.

      No worries - that's why we're linking you to the nodes that give tips on how to best ask questions. The better questions you ask, the faster and better we'll be able to help :-)

      I was just looking for some general directions as I am just crawling through the dark with this right now.

      "Code review" type questions are ok, I'd just suggest that you clearly label them as such. Otherwise, people will assume you just dumped a bunch of code on us, which is generally not considered polite, since it makes it look like you expect others to spend their free time going through a bunch of code that's not relevant to the problem.

      If you have specific problems, then as the others have been saying, the best way to go about asking for help is to reduce the code down to just the bare minimum needed for others to reproduce the problem (including runnable code, short example input, expected output for that input, and actual output including any error messages). In this regard, Short, Self-Contained, Correct Example is a good read. Narrowing down the code to only that portion which shows the problem not only helps us in providing you faster and better help, it often will help you see the bug more clearly. Also, it's important to Use strict and warnings, since they will help avoid some obvious mistakes. Two more very good reads are the Basic debugging checklist to help you locate the issue, and How do I post a question effectively?

      There are no hard guidelines being broken; just guidance for how to get better results faster next time your post.

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      A reply falls below the community's threshold of quality. You may see it by logging in.

      It's cool. If you read kennethk's link, you'll see that it says: "Include a minimal script that reproduces your problem and sample data (input)." We can answer better if we don't have to guess where the problem is.

      Interesting fact: while trying to find the minimum amount of script that reproduces a given problem, you will often find that the problem is not what you think it is.

      (The rude anonymonk is not me, I think kennethk is doing fine.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1184558]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found