Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Takeing the leading space out.

Status
Not open for further replies.

newtarge

ISP
Oct 27, 2003
21
0
0
US
I have a problem which I have tried many different thing to solve it and failed.

I am pushing info from a join statement

@vhostsall =`du -ks *`;


foreach (@vhostsall){
($f1,$f2) = split (/\s+/,$_);
$vall = join ("","(directory)",$f2," ","(size)",$f1," ","kilobytes\n");
push(@VH2, $vall);
}

the results of this make on line all the way to the left and the rest of the lines begin with 1 space. I put a \b after the \n in the join statement and it worked for when I printed it out, but when i tried to write it to a file it went back to the leading space on each line. If I use \n any where but in the join statement everything is smashed togather.
 
you might want to try chomping each line in the array before working with it:

foreach (@vhostsall){
chomp;
...
 
Thank you for the tip but it still did not work.

here is the result. notice how the 1st one is right.

(directory)abnonline (size)5822 kilobytes
(directory)beactiveamericaorg (size)2446 kilobytes
(directory)birchhortoncom (size)7732 kilobytes
(directory)blacksocietypages (size)21190 kilobytes
(directory)ccainstituteorg (size)15462 kilobytes
(directory)clarkeandsampson.com (size)7091 kilobytes
(directory)cvdassociatescom (size)1031 kilobytes
(directory)firstnightalexandriaorg (size)21360 kilobytes
(directory)hbwgroupcom (size)4176 kilobytes
(directory)htpasswd (size)1 kilobytes
(directory)idbfcorg (size)325 kilobytes
(directory)idodacom (size)357 kilobytes
(directory)inronlinecom (size)4274 kilobytes
(directory)mcaleesecom (size)18665 kilobytes
(directory)report (size)2 kilobytes
(directory)report.txt (size)1 kilobytes
(directory)stevengaffneycom (size)15275 kilobytes
(directory)sugar (size)93689 kilobytes

 
in this line:
$vall = join ("","(directory)",$f2," ","(size)",$f1," ","kilobytes\n");
get rid of the first "", why do you need them? so make it
$vall = join ("(directory)",$f2," ","(size)",$f1," ","kilobytes\n");
 
Can't get rid of it because it is the field seperator.
 
Can you do a regex to eliminate the space?

@vhostsall =`du -ks *`;


foreach (@vhostsall){
($f1,$f2) = split (/\s+/,$_);
$vall = join ("","(directory)",$f2," ","(size)",$f1," ","kilobytes\n");
$vall =~ s/^\s+//;
push(@VH2, $vall);
}
 
did a sample run with
@vhostsall = ("5822 abnonline", "2446 beactiveamericaorg", "7732 birchhortoncom");

foreach (@vhostsall){
chomp;
($f1,$f2) = split (/\s+/,$_);
$vall = join ("","(directory)",$f2," ","(size)",$f1," ","kilobytes\n");
push(@VH2, $vall);
}
open (FH, ">log.txt");
print FH @VH2;
close FH;

I assumed the contents of @vhostsall(see above) and it worked. result:
(directory)abnonline (size)5822 kilobytes
(directory)beactiveamericaorg (size)2446 kilobytes
(directory)birchhortoncom (size)7732 kilobytes

the only difference is the @vhostsall, post a print out of your @vhostsall
 
Believe it or not $vall = join ("","\b","(directory)",$f2," ","(size)",$f1," ","kilobytesn"); seemed to work,but when the form is mailed to me the results have

result
[]
result
[]
result

the substitution thing did not work either.
 
I'm curious, if you're joining scalars with the empty string, why not just concatenate instead of joining? If you wanted, you could just make one big interpolated string.

concatenated
[tt]$vall = "(directory)".$f2." "."(size)".$f1." "."kilobytes\n");[/tt]

interpolated
[tt]$vall = "(directory)$f2 (size)$f1 kilobytes\n");[/tt]

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
I figured out in debuggin where this happens.

it is in the part push(@VH2, $vall); before this it is correct after the push it is wrong.
 
I'm not positive, but isn't the \b being interpolated as a backspace control char. in this context? Would that explain the different behavior when writing to a file or printing to stdout?
 
No it is still off set whether I print to a file or STDOUT.
 
here is the whole script. maybe this help you see it better.

#!/usr/bin/perl
$server=`uname -n`;
chomp ($server);
$username="newtarg1";
chomp ($username);
$path="/usr/home/$username/chomp ($path);
$dtchk=`date`;
chomp ($dtchk);
($a1,$a2,$a3,$a4,$a5,$a6) = split (/\s+/,$dtchk);
$date = join ("",$a1," ",$a2," ",$a3," ",$a6);


$pathtomail="/usr/home/$username/var/mail";
$pathtologs="/usr/home/$username/$pathtohtdocs="/usr/home/$username/$pathtovhosts="/usr/home/$username/chomp ($pathtomail);
chomp ($pathtologs);
chomp ($pathtohtdocs);
chomp ($pathtovhosts);

$chkmail=`du -ks $pathtomail`;
($c1,$c2) = split (/\s+/,$chkmail);
$chkmail2 = join ("","(path)",$c2," ","(size)",$c1," ","kilobytes");
$chklogs=`du -ks $pathtologs`;
($d1,$d2) = split (/\s+/,$chklogs);
$chklogs2 = join ("","(path)",$d2," ","(size)",$d1," ","kilobytes");
$chkhtdocs=`du -ks $pathtohtdocs`;
($e1,$e2) = split (/\s+/,$chkhtdocs);
$chkhtdocs2 = join ("","(path)",$e2," ","(size)",$e1," ","kilobytes");
$chkvhoststotal=`du -ks $pathtovhosts`;
($f1,$f2) = split (/\s+/,$chkvhoststotal);
$chkvhoststotal2 = join ("","(path)",$f2," ","(size)",$f1," ","kilobytes");

chdir "$path" or die "the little piggy went wee wee all the way home";

$vhostsall ="du -ks *";
@vhostsall = qx ( $vhostsall );
#chomp ($vhostsall);


foreach $sentence(@vhostsall){
unless (($sentence =~ htpasswd) && ($sentence =~ report)){
($g1,$g2) = split (/\s+/,$sentence);
$vall = join ("","(directory)",$g2," ","(size)",$g1," ","kilobytes");
$vall .= "\n";
push(@VH2, $vall);
}
}
$vh3 .= "@VH2";
$quota=`quota -v`;
chomp ($quota);
$pathtoreportfile="/usr/home/$username/report.txt";

open REPORT, ">$pathtoreportfile" or die "no file exists";
print REPORT "web directory usage report for server $server\n";
print REPORT "$date\n";
print REPORT "---------------------------------------------\n";
print REPORT "$chkmail2\n";
print REPORT "$chklogs2\n";
print REPORT "$chkhtdocs2\n";
print REPORT "\n";
print REPORT "$server\n";
print REPORT "\n";
print REPORT "$vh3";
print REPORT "---------------------------------------------\n";
print REPORT "$chkvhoststotal2\n";
print REPORT "\n";
print REPORT "$quota\n\n";
close REPORT;

$mailme=&quot;mail -t info\@newtarget.com < /usr/home/$username/report.txt&quot;;
system ($mailme);
 
Ok I figured out hos to fix the problem, now when I try to mail it to my self and it is from a solaris server, when i get them mail the part of it with the list is all smooshed togather.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top