Sponsored Content
Full Discussion: Perl Query
Top Forums Programming Perl Query Post 302766427 by durden_tyler on Monday 4th of February 2013 04:52:18 PM
Old 02-04-2013
Quote:
Originally Posted by gsiva
...
Same way, for the files under the directory is not getting the output properly.
Code:
$mode = sprintf "%04o", (stat '/etc/rc.d/[rc]*.d') [2] & 07777;
if($mode eq "0755")
{
print "GOOD: AD.1.8.18: The file /etc/rc.d/[rc]*.d exists and had permission 0755\n\n";
}
else
{
print "BAD: AD.1.8.18: The file /etc/rc.d/[rc]*.d exists and does not have permission 0755\n\n";
}
print `ls -ld /etc/rc.d/[rc]*.d`;
print "\n";

OUTPUT:

BAD: AD.1.8.18: The file /etc/rc.d/[rc]*.d exists and does not have permission 0755

drwxr-xr-x 2 root root 4096 Oct 24 15:55 /etc/rc.d/rc0.d
drwxr-xr-x 2 root root 4096 Oct 24 15:55 /etc/rc.d/rc1.d
drwxr-xr-x 2 root root 4096 Jan 14 13:24 /etc/rc.d/rc2.d
drwxr-xr-x 2 root root 4096 Jan 14 13:24 /etc/rc.d/rc3.d
drwxr-xr-x 2 root root 4096 Oct 24 15:55 /etc/rc.d/rc4.d
drwxr-xr-x 2 root root 4096 Jan 14 13:24 /etc/rc.d/rc5.d
drwxr-xr-x 2 root root 4096 Oct 24 15:55 /etc/rc.d/rc6.d

The output should be GOOD.
That's because Perl looks for a file that is literally called "/etc/rc.d/[rc]*.d", and since it could not find it, "stat" returns an empty array and the value of $mode is "0000".
Since that is not equal to "0755", the control goes to the "else" branch and the message you see is printed. Notice that despite the fact that the message says "... file exists...", you are not testing the existence of the file.
The output of "ls" is printed correctly because you pass the "ls" command to the shell, which expands the regular expression and lists all files that match it.

- Use the glob function of Perl to loop through all files of interest.
- Add the following two lines at the beginning of your program:

Code:
use strict;
use warnings;

The "use warnings" would've thrown a warning in your case, if it had been set.

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Incorrect SQL query in perl

I the the following perl script, however it does not return anything. Did i form my syantax wrongly? $sth=$dbh->prepare("select a.rowid,a.* from Table1 a where a.field1 = \'$Indicator1\' and a.schedule = \'$Indicator2\' and a.lastdate <= sysdate"); $sth->execute() ... (1 Reply)
Discussion started by: new2ss
1 Replies

2. Shell Programming and Scripting

Perl CGI Query

Hi All, This is quite a high level question so I appologise as if it sounds a bit woolly! I'm running a script via apache's cgi-bin that calls another Perl script (from a browser): http://192.168.000.000/cgi-bin/run_script.pl?SCRIPT=test.pl&text=RANDOM+TEXT&INPUT1=444444444444 This... (4 Replies)
Discussion started by: pondlife
4 Replies

3. Shell Programming and Scripting

perl query

a file test.dat has the following David Veterinarian John Orthopedist Jeff Dentist perl -p -e "s/\s*(\w+).*/$1/;" test.dat ......will print David Jonh Jeff how does the part in double quotes work out.... (1 Reply)
Discussion started by: bishweshwar
1 Replies

4. UNIX for Dummies Questions & Answers

Query in perl

can any1 give me line by line explanation for the following perl script as i dunno perl .. n i have searched in google .. but still thn i wanna confirm my findings fro perl experts :mad: perl -e 'while (<>) { print; $num = 2 if /fail_halt/i; $num = 1 if (/failure/i && ($num < 1)); }... (2 Replies)
Discussion started by: Dana Evans
2 Replies

5. UNIX and Linux Applications

Perl - PostGreSql query

Guys, I guess, I posted something in the wrong forum. Here it is - https://www.unix.com/shell-programming-scripting/67395-perl-postgrepsql-question.html Can you please help me with this? Regards, garric (0 Replies)
Discussion started by: garric
0 Replies

6. Shell Programming and Scripting

Perl Query Regarding format

Hello people. I have got the following script QM=ARGV; open (CHS_OUT, "echo 'DISPLAY QSTATUS(SYSTEM.CLUSTER.MY.QUEUE) all'|runmqsc $qm|"); while (<CHS_OUT>) { if ( /QUEUE\(/ ) { $QueueName = ValueParser("QUEUE", 6); } if ( /IPPROCS\(/ ) { $InpProcs = ValueParser("IPPROCS", 8); #print... (3 Replies)
Discussion started by: King Nothing
3 Replies

7. Shell Programming and Scripting

Perl - CAPTURE query

When i run script with option 1 it works, however if I assign path to variable $tmpfile and try to use that it writes to $tmpfile and not /var/tmp/abc.tmp, what am I missing? 1. open (CAPTURE, '>>tmpfile'); print CAPTURE "$T1,$T2,$T3"; close (CAPTURE); 2. my $tmpfile='/var/tmp/abc.tmp';... (10 Replies)
Discussion started by: gefa
10 Replies

8. Shell Programming and Scripting

perl- oracle sql query

Hi, I am new to perl.How to query oracle database with perl??? Thanks (1 Reply)
Discussion started by: tdev457
1 Replies

9. Shell Programming and Scripting

Formating of query variable in perl

Hi , I am facing error in perl when I assign a below query in a varibale $query because of new line charchters $query= SELECT XYZ , ABC , c2 , c3 , c4 FROM t1 how can i get rid of new line charchters with out changing the... (2 Replies)
Discussion started by: gvk25
2 Replies

10. Shell Programming and Scripting

From perl program query is not executed.

I have tried executing one particular query through perl.But I am unable to get the result. When I tried to execute the sysdate query its working when I executed my perl code. The below query doesn't work. QUERY 1:my $sql ="select name from tab where rownum <6"; Received ora error... (23 Replies)
Discussion started by: ramkumar15
23 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy