Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Additional headers

by pragovnj (Acolyte)
on Feb 13, 2020 at 16:48 UTC ( [id://11112924]=perlquestion: print w/replies, xml ) Need Help??

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

I have inherited this perl code and have an issue of additional headers. Not sure where from the code, these headers without data are coming from

This is the code

#!/usr/bin/perl require 'ConvertDates.pl'; use DBI; use Date::Manip ; use CGI; $parms = CGI->new; #parse parameters $start_date = $parms->param("sd"); $end_date = $parms->param("ed"); $separator= $parms->param("sep"); $HOME="/export/home/pmdss"; $CONFIG="${HOME}/config"; #$row=0; $rows=0; $NumOfRts=1500; $CntOfRts=0; print "Content-type: text/plain\n\n" ; chomp($ds_mach=`cat ${CONFIG}/BigIron`); chomp($dr_mach=`cat ${CONFIG}/BigIronDR`); system("/usr/sbin/ping $ds_mach >/dev/null 2>/dev/null"); if ( ($? >> 8) eq 0 ) { $id = "pmdss\@$ds_mach"; } else { system("/usr/sbin/ping $dr_mach >/dev/null 2>/dev/null"); chomp($ds_mach=`cat ${CONFIG}/BigIron`); chomp($dr_mach=`cat ${CONFIG}/BigIronDR`); system("/usr/sbin/ping $ds_mach >/dev/null 2>/dev/null"); if ( ($? >> 8) eq 0 ) { $id = "pmdss\@$ds_mach"; } else { system("/usr/sbin/ping $dr_mach >/dev/null 2>/dev/null"); if ( ($? >> 8) eq 0 ) { $id = "pmdss\@$dr_mach"; } else { print "A serious error has occurred, please contact pr +oduction support or try again later...\n" ; exit 0; } } $cmd = "ssh $id '. ~/q; \$Q/AgnEthernetList3-1.X -s $start_date -e $en +d_date' 2>/dev/null |"; #print "$cmd\n"; open (input , $cmd); while ($INPUT_LINE = <input>) { chomp($INPUT_LINE); ($dat{l_node}, $dat{l_slot}, $dat{l_ifNum}, $dat{r_node}, $dat +{r_slot}, $dat{r_line}, $dat{r_port}, $dat{kbps}, $dat{subnetwork }, $dat{subnetwork2}, $dat{r_domain_id}, $dat{icore_domid}, $dat{cust +_port}, $dat{track_port}, $dat{vlan_stacking_inv}, $dat{cos_level }) = split(/ /, $INPUT_LINE); $KEY = $dat{l_node} . "." . $dat{l_slot} . "." . $dat{l_ifNum +}; $key2 = int($CntOfRts++/$NumOfRts); $cmd = "ssh $id '. ~/q; \$Q/AgnEthernetList3-1.X -s $start_date -e $en +d_date' 2>/dev/null |"; #print "$cmd\n"; open (input , $cmd); while ($INPUT_LINE = <input>) { chomp($INPUT_LINE); ($dat{l_node}, $dat{l_slot}, $dat{l_ifNum}, $dat{r_node}, $dat +{r_slot}, $dat{r_line}, $dat{r_port}, $dat{kbps}, $dat{subnetwork }, $dat{subnetwork2}, $dat{r_domain_id}, $dat{icore_domid}, $dat{cust +_port}, $dat{track_port}, $dat{vlan_stacking_inv}, $dat{cos_level }) = split(/ /, $INPUT_LINE); $KEY = $dat{l_node} . "." . $dat{l_slot} . "." . $dat{l_ifNum +}; $key2 = int($CntOfRts++/$NumOfRts); ($nspString{$key2} = $nspString{$key2} . ":") if ($nspString{$ +key2} ne ""); $nspString{$key2} = $nspString{$key2} . "$dat{l_node},$dat{l_s +lot},$dat{l_ifNum}"; $arraykey{$KEY} = $KEY; $r_node{$KEY} = $dat{r_node}; $r_slot{$KEY} = $dat{r_slot}; $r_port{$KEY} = $dat{r_port}; $kbps{$KEY} = $dat{kbps}; $subnetwork{$KEY} = $dat{subnetwork}; $subnetwork2{$KEY} = $dat{subnetwork2}; $r_domain_id{$KEY} = $dat{r_domain_id}; ($r_domain_id{$KEY} = $dat{icore_domid}) if ($r_domain_id{$KEY +} eq ""); $cust_port{$KEY} = $dat{cust_port}; $track_port{$KEY} = $dat{track_port}; $vlan_stacking_inv{$KEY} = $dat{vlan_stacking_inv}; $cos_level{$KEY} = $dat{cos_level}; $rows = $rows + 1; } close (input); if ($rows > 0) { print "l_node\t" . "l_slot\t" . "l_port\t" . "r_node\t" . "r_slot\t" . "r_line\t" . "r_port\t" . "kbps\t" . "subnetwork\t" . "toNetwork\t" . #"pvcs\t" . #"lcir\t" . #"rcir\t" . "domain\t" . "icore_domid\t" . "cust_port\t" . "track_port\t" . "vlan_stacking_inv\t" . "cos_level\t" . "PvcCount"; # "placeholder"; foreach $key (keys arraykey) { ($l_node,$l_slot,$l_ifNum) = split(/\./, $key); if (substr($l_node,10,3) eq "ME2") { if ($l_slot >= 10000) { if ( substr($l_slot,1,1) eq "0" ) { $L_SLOT = substr($l_slot,2,1) +. "-" . substr($l_slot,4,1) ; } else { $L_SLOT = substr($l_slot,1,2) +. "-" . substr($l_slot,4,1) ; } } else { $L_SLOT = $l_slot ; } } else { $L_SLOT = $l_slot ; } if (TRIM($toNetwork{$r_domain_id{$key}}) ne "") { $_2Network = $toNetwork{$r_domain_id{$key}}; } else { $_2Network = $subnetwork2{$key}; } print "\n" . $l_node . "\t" . $L_SLOT . "\t" . $l_ifNum . "\t" . $r_node{$key} . "\t" . $r_slot{$key} . "\t" . $r_line{$key} . "\t" . $r_port{$key} . "\t" . $kbps{$key} . "\t" . $subnetwork{$key} . "\t" . $_2Network . "\t" . #$pvcs{$key} . "\t" . #$lcir{$key} . "\t" . #$rcir{$key} . "\t" . $domain{$r_domain_id{$key}} . "\t" . $icore_domid{$key} . "\t" . $cust_port{$key} . "\t" . $track_port{$key} . "\t" . $vlan_stacking_inv{$key} . "\t" . $cos_level{$key} . "\t" . $PvcCount{$key}; } } else { print `cat nodata`; } sub TRIM { $A = shift; $_ = $A; s/^ +//; s/ +$//; $A = $_; return $A; }

I get data correctly for the 17 fields with headers but then I see additional columns from R to AG with no data. Where is it picking the additional columns and how to prevent it?

Replies are listed 'Best First'.
Re: Additional headers
by footpad (Abbot) on Feb 13, 2020 at 19:02 UTC

    Hi pragovnj,

    If you're new to the site, welcome. I see you have eight other posts, so I'm a little uncertain the next question is entirely necessary, but...um...are you sure this is a Perl-related issue?

    Based on the program you posted, it looks like your data file should only contain 17 fields (assuming the file you're asking about was created by the program you posted). Have you tried looking at the data file from a text editor, just to be sure?

    If you're opening the file in a different program, such as Excel or some other spreadsheet, it's possible the "extra fields" you're seeing are "helpfully" added by the program to give you room to work in. If you don't save the data file from this program, there shouldn't be any additional data in your file, blank or otherwise.

    For what it's worth, the site is devoted to the Perl programming language and most monks assume that questions have something or other to do with coding Perl. Are you sure this is the right place for the help you're looking for?

    If we've misunderstood the nature of your question, please feel free to clarify and re-post.

    --f

    P.S. If your previous question about the tab delimiters pertains to this particular program, you would change the tabs to vertical pipes by replacing the "\t"s with "|".

    P.P.S. (If you're unsure about how to do this, may I humbly recommend obtaining a copy of Learning Perl? (The latest edition is a bit dated, but if the online materials aren't helping, this might be just the thing to help you.)

      Thanks for the response. The data fields and values are correctly populated on the browser. But when I try to import into Excel, it shows fields with data but also additional columns with no data. I am not sure whether it is added by the program. When I used vertical pipe, I do not see additional columns created but the last field had data value and these pipe symbols next to them!

Re: Additional headers
by NetWallah (Canon) on Feb 14, 2020 at 04:42 UTC
    You seem to have ignored the good advice in response to this same code posted in your previous post.

    The code posted here does not compile. Errors are:

    Type of arg 1 to keys must be hash or array (not constant item) at tes +t1.pl line 125, near "arraykey) " Missing right curly or square bracket at test1.pl line 181, at end of +line syntax error at test1.pl line 181, at EOF Execution of test1.pl aborted due to compilation errors.
    although the compile errors are trivial to fix (Add % before arraykey, and close two curly braces).

    After fixing your code to compile, we are unable to take diagnostics further without knowing what the incoming data looks like.

    It is possible that one of your pieces of data has extra tab characters, which would generate additional columns.

    As others have suggested, a short, self-contained example demonstrating your issue , and including what the output looks like would really help.

    update: Fixed typo . Thanks LanX.

                    "From there to here, from here to there, funny things are everywhere." -- Dr. Seuss

Re: Additional headers
by LanX (Saint) on Feb 13, 2020 at 16:56 UTC
    Regarding your last thread ... Pipe delimiter ...

    Could it be that you are confusing HTTP-headers with table-headers in your CSV or Excell ?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      From my code, I just need 17 columns and nothing more

      Thanks, Pragov
        Maybe you should hire a programmer.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Additional headers
by bliako (Monsignor) on Feb 13, 2020 at 23:46 UTC

    the code you posted is sunstandard (edit: though inten(da)tions are good :) ). Show more effort please.

    chomp($ds_mach=`cat ${CONFIG}/BigIron`); chomp($dr_mach=`cat ${CONFIG}/BigIronDR`); system("/usr/sbin/ping $ds_mach >/dev/null 2>/dev/null"); if ( ($? >> 8) eq 0 ) { $id = "pmdss\@$ds_mach"; } else { system("/usr/sbin/ping $dr_mach >/dev/null 2>/dev/null"); chomp($ds_mach=`cat ${CONFIG}/BigIron`); chomp($dr_mach=`cat ${CONFIG}/BigIronDR`); system("/usr/sbin/ping $ds_mach >/dev/null 2>/dev/null");

Log In?
Username:
Password:

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

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

    No recent polls found