Hi!

I have a question, not even sure where to start coding on. I have a file that has a field in brackets that I want to export to another file. For some reason it doesn't pick up the file unless the brackets are removed.
Here's the script that works without brackets:

#$slotnumber=0; $dpdrivloc = "Trinity"; open(DPSLOTFILE, "< c:\\test.txt") or die "Can't open file: $!"; while ( <DPSLOTFILE> ) { if ( /$dpdrivloc:\s*(\d+)/ ) { print "Slot for $dpdrivloc: $1\n"; } } #system("c:\\ipbat.bat"); close DPSLOTFILE;

The file has brackets around "Trinity" and won't read data unless the brackets are removed.
The file works if the file looks like:

Label Location Time NKL0800 MSL6000 Trinity: 7 1800

The code doesn't work when file is like:
Label Location Time [NKL0800] [MSL6000 Trinity: 7] 1800

Unfortunately the file that needs to be read is like the second one. What I would like to do is take the fields inside [] and copy the data to a new file for reading. Any ideas (stripping out from [], I can handle the file I/O)???

Edited by BazB fixed formatting


In reply to Remove field inside [ ] brackets by jamen_98

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.