LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   what is the echo command in perl? (https://www.linuxquestions.org/questions/programming-9/what-is-the-echo-command-in-perl-264800/)

hamish 12-10-2004 05:27 AM

what is the echo command in perl?
 
Hey

I'm writing a perl script at the moment to check my users quotas. I have used bash scripts before, and would like to know the equivilent perl command to the bash "echo" command.

The reason being that part of my code is to echo to the outcome of a command:

Code:

echo "$(repquota -a)" > temp
What will this be in perl?

Thanks in advance.
Hamish

SiLiCoN 12-10-2004 05:49 AM

hey hamish,

u can use "print" or even echo itself.

#!/usr/bin/perl -w
my @array = `repquota -a`;
foreach my $record(@array)
{
print "$record\n";
}

that's it..!!!

Cheers

sirclif 12-10-2004 11:49 AM

the system() functionis also helpful if you just need to run some commands.

system("echo $(repquota -a`");

it basically just inserts what is betweent he "" into a command line and enters it

mayur 12-14-2004 06:53 AM

you can also use, printf("\n"); like what we do in C

bigearsbilly 12-14-2004 07:21 AM

firstly why are you doing
Quote:

echo "$(repquota -a)" > temp
why not simply
Code:

repquota -a > temp

you can't simply print the output of a command
(I assume you mean calling a system command from perl?)

you can use sytem which will print out anyway.

if you want to save to a file you can use system
Code:

system("repquota -a > temp")
or using 'open' in perl
you can do operations line by line of the output:

(this example will simply print output from find)

Code:


    open OUT, "2>&1  /usr/bin/find .  |";
    print  while (<OUT>);


hamish 12-14-2004 08:31 AM

hey

thanks for all the feedback guys. I now have it working.

Cheers
Hamish


All times are GMT -5. The time now is 10:54 PM.