Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Welcome to Perl jwashburn. ww already gave some good advice. I'd like to add - play. Try stuff out. Do things a little bit at a time, but each time try something new. When you run into a brick wall, come here and ask about it.

For your current problem, take it a little bit at a time. So far you have a file open, but for test purposes there is a trick you can do: include the data in the program like this:

use strict; use warnings; while (<DATA>) { chomp; print "$_\n"; } __DATA__ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * File: G:\xcacls.txt Permissions: Type Username Permissions Inheritance + Allowed BUILTIN\Administrators Full Control This Folder Onl +y Allowed \Everyone Read and Execute This Folder Onl +y Allowed NT AUTHORITY\SYSTEM Full Control This Folder Onl +y * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* *

DATA is a magic file handle (Perl has a lot of magic) that you don't have to open and that is used to read the stuff following __DATA__ or __END__. The chomp removes the line seperator character sequence from the end of the string. In this case the string is in the default variable $_. So the script reads the data following __DATA__ a line at a time, removes the line end sequence from each line, then prints it (putting the line end sequence back in).

Now you can focus on finding stuff.

use strict; use warnings; while (<DATA>) { chomp; if (m/^File: (.*)/) { print "$1 allows:\n"; } elsif (m/^Allowed (.*)/) { print "$1\n"; } } __DATA__ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * File: G:\xcacls.txt Permissions: Type Username Permissions Inheritance + Allowed BUILTIN\Administrators Full Control This Folder Onl +y Allowed \Everyone Read and Execute This Folder Onl +y Allowed NT AUTHORITY\SYSTEM Full Control This Folder Onl +y * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* *

The additional magic here is using if and regexes to find and extract interesting data. The ^File at the start of the regex says 'match the text File: at the start of the string. Which string? The one in the default variable $_. The (.*) is a capture match. The brackets mean 'capture whatever is matched inside the brackets'. The dot means 'match any character' (not quite the full story, but enough for now). The asterix means 'match the thing to the left as many times as possible'.

In the print the special variable $1 is used to give the stuff captured.

Ok, there's a start. The next step is to figure out what and how you want formatted using HTML and pull out the pieces, possibly using more regexs, or more likely by using substr (because the files are using fixed size fields).

After that you can put your file handling back in and print to another file rather than to the console and you should be in business.

Note that it is strongly recommended that you use the three parameter open rather than the two parameter open that you did in your sample code. THe three parameter open looks like:

open inFile, '<', 'inFileName';

It avoids various security issues and makes it clear that the file is being opened for input.


DWIM is Perl's answer to Gödel

In reply to Re: PERL newbie Cant figure out where to start by GrandFather
in thread PERL newbie Cant figure out where to start by jwashburn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found