How about something like this:

  next unless m:(\d\d\d\d)/(\d\d)/(\d\d):;
  $start_date = "$1$2$3";


On Wed, Nov 2, 2011 at 4:07 PM, Paul Rousseau
<paulrousseau...@hotmail.com>wrote:

>  Hello Perl folks,
>
>
> I would like to know if there is an eloquent way of extracting a date
> string from a file.
>
> My code goes like this:
>
>    open (INFILE, "<$sourcedir\\$filename") || die "Can not open
> $sourcedir\\$filename $!\n";
>    @filecontents = <INFILE>;
>    close INFILE;
>    @filecontents = map {chomp; $_} @filecontents;
>
> #
> # Within the file contents, look for the text, CurrentWeekLabel
> #
> # Here is a text sample.
> #
> #   <div style="TEXT-ALIGN: center; min-width: 750px">
> #    <div style="OVERFLOW: hidden; HEIGHT: 20px; TEXT-ALIGN: center"><span
> id="CurrentWeekLabel">Week Of: </span><span id="StartWeekLabel"
> style="font-weight:bold;">2011/10/29</span><span id="Label6"
> style="font-weight:bold;"> - </span><span id="EndWeekLabel"
> style="font-weight:bold;">2011/11/04</span></div>
> #    <div style="OVERFLOW: hidden; HEIGHT: 24px; TEXT-ALIGN: center"><a
> id="PreviousWeekLinkButton" class="LinkButton"
> href="javascript:OnPreviousWeekLinkButtonClick ()"
> href="javascript:__doPostBack('PreviousWeekLinkButton','')">Prev</a><span
> id="Label20">&nbsp;|&nbsp;</span><a
> onclick="SelectWeekButtonClick('PopupCalendar1', 'SelectWeekLinkButton');
> return false;" id="SelectWeekLinkButton" class="LinkButton"
> href="javascript:__doPostBack('SelectWeekLinkButton','')">Select
> Week</a><span id="Label8">&nbsp;|&nbsp;</span><a id="NextWeekLinkButton"
> class="LinkButton" href="javascript:OnNextWeekLinkButtonClick ()"
> href="javascript:__doPostBack('NextWeekLinkButton','')">Next</a></div>
> #    <div style="OVERFLOW: hidden; OVERFLOW:visible; TEXT-ALIGN:
> center"><span id="StatusLabel" class="StatusLabel"></span></div>
> #   </div>
> #
> # Obtain the year, month and day following the text, StartWeekLabel
> #
>   @ans = grep (/StartWeekLabel.+\>(\d{4})\/(\d{2})\/(\d{2})\<\/span/si,
> @filecontents);
> #
> # Build the start date from the matches.
> #
> $start_date = $1 . $2 . $3
>
> I was wondering if there was a neat way to avoid using @ans as a temporary
> variable, and extract the "2011/10/29" straight into $start_date so that
> $start_date = "20111029"
>
> Thank you
>
> Paul Rousseau
> 403 776 4293
>
>
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>


-- 
"The very nucleus of Character: to do what you know you should do, when you
don't want to do it." Stephen Covey
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to