Sponsored Content
Top Forums Shell Programming and Scripting Trivial perl doubt about FILE Post 302542626 by getmmg on Thursday 28th of July 2011 07:56:53 AM
Old 07-28-2011
Quote:
Originally Posted by royalibrahim
Hi,

In the following perl code:

Code:
#!/usr/bin/perl -w
 
if (open(FILE, "< in_file")) {
    while (<FILE>) {
        chomp($_);
        if ($_ =~ /patt$/) {
            my $f = (split(" ", $_))[0];
            print "$f\n";
        }
    }
    close FILE;
}

Why changing the "FILE" as "$FILE" gives error in the while loop and in the close statement?

FILE is the name of the file handle,
in_file is the name of the file you are trying to read.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies

2. UNIX for Dummies Questions & Answers

File Transfer that is not so trivial I guess

I have three computers A, B and C. To login to B and C I should use A because it has a SSH key. I don't have any other way of accessing these two computers. Now, if I need to transfer a file between B and C, I am unable to find a way that would work... because I don't know how to authenticate... (1 Reply)
Discussion started by: Legend986
1 Replies

3. Shell Programming and Scripting

Perl script doubt?

Dear friends, I have two files. In first file first column ($1), i have numbers. The second file containes, the same number in the fourth column($4). I need a output file, matching the first file column 1 with second file column 4. The main thing is the output file lines will be sorted... (4 Replies)
Discussion started by: vasanth.vadalur
4 Replies

4. Programming

A trivial XOR doubt in a program

Hi, I am trying to reverse a string using the following program utilizing the Exclusive OR bit operation: int main() { char str = "Quraish"; char *p = str, temp; char *q = str + strlen(str) - 1; while ( p != q ) { if (*p != *q) { *p ^= *q; *q ^= *p; *p ^= *q;... (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. Shell Programming and Scripting

Perl map doubt

Hello , Please can someone tell me what exactly happens when the below filehandler is chomped into an array and later mapped. $lcpLog="logcopy\@".getTimestamp."\log"; open CFg ,"< $lcpcfg"; chomp(@cfg = <CFG>); close CFG; @cfg=grep { $_ ne ' ' } map { lc + (split /\s*\/\//) }... (0 Replies)
Discussion started by: rmv
0 Replies

6. Shell Programming and Scripting

Doubt in Perl Variable declaration

Anyone please say what is the difference between $var and ${var} in perl Sometimes $var used and sometimes ${var} used in same program. Thanks in Advance, Prabhu ---------- Post updated at 09:34 AM ---------- Previous update was at 05:59 AM ---------- Any one please clarify (1 Reply)
Discussion started by: prsampath
1 Replies

7. Shell Programming and Scripting

Doubt in this trivial awk code

Hi, What is the difference in the following two awk one-liners? awk -F, '{s++} END {if (s == 1 && $4 > "09:10:00") {print $2, $4}}' f1 awk -F, '{s++} s == 1 && $4 > "09:10:00" {print $2, $4}' f1 Even though, all the 2nd column values have duplicate records, the first code does not give any... (4 Replies)
Discussion started by: royalibrahim
4 Replies

8. Programming

Trivial doubt about C function pointer

Hi, In the below C code, #include <stdio.h> void print() { printf("Hello\n"); } int main() { void (*f)() = (void (*)()) print; f(); (*f)(); } I wonder, how the syntaxes "f()" and "(*f)()" are treated as same without any error? Is this an improvement or ANSI/ISO... (1 Reply)
Discussion started by: royalibrahim
1 Replies

9. Shell Programming and Scripting

perl doubt

Hi, Please help me to understand the following code: perl -lne 'print if "$_ " =~ /(5 (?:\d+ ){5})\1/' What the regular expression "?:" does? Also, whether the expression "\1" is the same as in sed (i.e) printing the elements inside pair of parentheses? (3 Replies)
Discussion started by: royalibrahim
3 Replies

10. Shell Programming and Scripting

Non trivial file splitting, saving with variable filename

Hello, Although I have found similar questions, I could not find advice that could help with our problem. The issue: We have a few thousands text files (books). Each book has many chapters. Each chapter is identified by a cite-key. We need to split each of those book files by... (4 Replies)
Discussion started by: samask
4 Replies
PFUNC(1)						User Contributed Perl Documentation						  PFUNC(1)

NAME
pfunc - grep for perl functions SYNOPSIS
pfunc subroutine FILES... DESCRIPTION
pfunc searches the named FILES for all calls to the given subroutine. It will report back the file and line number each call is found on along with what sort of call it is function foo() class method Class->foo() object method $obj->foo() EXAMPLE
$ pfunc isa /usr/share/perl/5.6.1/*.pm Called as function in /usr/share/perl/5.6.1/CGI.pm at line 316 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 327 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 397 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 494 Called as function in /usr/share/perl/5.6.1/CGI.pm at line 495 Called as object method in /usr/share/perl/5.6.1/CPAN.pm at line 4957 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 191 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 218 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 248 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 251 Called as function in /usr/share/perl/5.6.1/Dumpvalue.pm at line 254 Called as object method in /usr/share/perl/5.6.1/Shell.pm at line 28 Called as object method in /usr/share/perl/5.6.1/base.pm at line 12 NOTES
Its not fast, but its accurate. AUTHOR
Michael G Schwern <schwern@pobox.com> SEE ALSO
Module::Info perl v5.12.1 2002-12-05 PFUNC(1)
All times are GMT -4. The time now is 05:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy