Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: PHP to PERL ?

by Delusional (Beadle)
on Dec 28, 2005 at 11:03 UTC ( [id://519514]=note: print w/replies, xml ) Need Help??


in reply to PHP to PERL ?

Just as an example:

Script file
my $file = "somefile.txt"; print "Opening and displaying $file:\n"; include($file); print "Complete\n"; exit; sub include { my $include = $_[0]; open(INFILE,"<$include") || die "Can't find or open $include\n"; @FileContent = <INFILE>; close(INFILE); foreach $line (@FileContent) { print $line; } }

somefile.txt
Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10

Again, just as an example, and not exactly 'perfect'. As mentioned, there isn't any one way to do anything in Perl. This example, assumes that the file passed to the sub (function) include does not contain any program code, rather only information to display (which can be html code).

So, assuming your going to use this, you would copy the sub include to some file you include in your file/script, or in the primary file/script. Then place a call to include(), passing a single command, that being the file name to open, and display. Thus, the include() could be use in several locations, with each call to it having any file name you desire.

But as I said, this is just an example, and I should point out, not really clean. However, it does execute and displays 'correctly'. The output of this example:
Opening and displaying somefile.txt: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Complete

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found