[1] If you have ever used an Internet browser you may have come across links that don't go anywhere (broken links) which are extremely annoying. Part of the challenge of making programs that put in hypertext links is ensuring the link the program puts in always has an associated destination or anchor. An associated problem is ensuring that jump destinations or anchors are unique. i.e. jump destinations are never repeated.
What variable type in Perl could you use, that would identify repeated jump destinations.
Write a subroutine that uses the above data type (you can assume the data type is a global variable), takes as input a jump destination and prints to STDOUT a warning message if it has already received the input jump destination.
Below is a skeleton subroutine you should base your answer on:
[2] What will the following subroutine return (DoSomething) given the input value below:sub CheckJumpDestination { my($jump_destination) = @_; if ( # Your code here ) { # Your code here. } else { # Your code here. } }
%unreported_case_list = ( '30/11/90, cp654/88' => '1' ); &DoSomething('In <FD:"Case Title">Bradburn v Harris</FD:"Case Title"> +<FD:"Case Citation">30/11/90, Fisher J, HC Auckland CP654/88</FD:"cas +e Citation"> Fisher J was dealing with a counterclaim for interest un +der two vendor mortgages.'); sub DoSomething { my($line) = @_; my($new_line, $citation, $start_of_line, $jump_destination) = ('','','','',''); DEBUG('c',"IN DoSomething\n"); while ( $line =~ s{^ ( .*? ) < FD:"Case \s Citation" > ( .+? ) </ +FD:"Case \s Citation" > }{}xi ) { $start_of_line = $1; $citation = &StripWhiteSpace($2); if ( $citation !~ m{ \b tclr \b }xi ) { $jump_destination = lc($citation); if ( exists($unreported_case_list{$jump_destination}) ) { $new_line .= "$start_of_line<FD:\"Case Citation\"><JL: +\"Internal Jump\",\"$jump_destination\">$citation</JL></FD:\"Case Cit +ation\">"; $unreported_jl_count++; } elsif ( $citation =~ m{ ( \d{1,2} / \d{1,2} / \d{4} | \d{2 +} ) , .+? ( [a-z]+\d+ (?: / \d+ )? ) }xi ) { $jump_destination = &NormaliseDate("$1").', '.lc($2); if ( exists($unreported_case_list{$jump_destination} +) ) { $new_line .= "$start_of_line<FD:\"Case Citation\"> +<JL:\"Internal Jump\",\"$jump_destination\">$citation</JL></FD:\"Case + Citation\">"; $unreported_jl_count++; } else { $new_line .= "$start_of_line<FD:\"Case Citation\"> +$citation</FD:\"Case Citation\">"; } } else { $new_line .= "$start_of_line<FD:\"Case Citation\">$cit +ation</FD:\"Case Citation\">"; } } else { $new_line .= "$start_of_line<FD:\"Case Citation\">$citatio +n</FD:\"Case Citation\">"; } } $new_line .= $line; DEBUG('c',"LEAVING DoSomething\n"); return($new_line); } #-------------------------------NormaliseDate------------------------- +---- # INPUT # $date # # RETURNS # normalised date # # Normalises the input date to dd/dd/dddd format. #--------------------------------------------------------------------- +---- sub NormaliseDate { my($date) = @_; my($day, $year, $month) = (0,0,0); DEBUG('c',"IN NormaliseDate\n"); if ( $date =~ m{^ ( \d{1,2} ) / ( \d{1,2} ) / ( \d{4} | \d{2} ) $} +x ) { $day = $1; $month = $2; $year = $3; if ( length($day) == 1 ) { $day = '0'.$day; } if ( length($month) == 1 ) { $month = '0'.$month; } if ( length($year) == 2 ) { $year = '19'.$year; } } DEBUG('c',"LEAVING NormaliseDate\n"); return("$day/$month/$year"); } #-----------------------------StripWhiteSapce------------------------- +---- # INPUT # $line # # RETURNS # $line # # Removes leading and trailing whitespace from the input string. #--------------------------------------------------------------------- +---- sub StripWhiteSapce { my($line) = @_; DEBUG('c',"IN StripWhiteSapce \n"); $line =~ s{^ \s+ }{}x; $line =~ s{ \s+ $}{}x; DEBUG('c',"LEAVING StripWhiteSapce \n"); return($line); }
update (broquaint): added formatting
update 2 (broquaint): title change (was Perl Newbe Urgently Needs Help)
In reply to Perl junior entreats monastery for course help by spyder78
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |