Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/import_subjects broken - no subjects imported #291

Closed
drtjmb opened this issue Feb 2, 2015 · 3 comments · Fixed by #292
Closed

bin/import_subjects broken - no subjects imported #291

drtjmb opened this issue Feb 2, 2015 · 3 comments · Fixed by #292
Assignees
Labels

Comments

@drtjmb
Copy link
Member

@drtjmb drtjmb commented Feb 2, 2015

 63 
 64         # percent-decode "%3A" to ":"
 65         @vals = map { s/%3A/:/g } @vals;
 66 

Will effectively erase the content of @vals so no subject data is imported.

@phluid61 - don't modify $_ in a map, and remember that the output of s/// is the success code not the altered string.

Try:

@vals = map { s/%3A/:/g; $_ } @vals; # still modifies $_

or better

@vals = map { ( my $s = $_ ) =~ s/%3A/:/g; $s } @vals;
@phluid61
Copy link
Contributor

@phluid61 phluid61 commented Feb 2, 2015

Sorry, my mistake was in assigning it back to @vals. What I meant to write was:

map { s/%3A/:/g } @vals;

Is there a reason not to modify $_?

phluid61 added a commit to QUTlib/eprints that referenced this issue Feb 2, 2015
@phluid61 phluid61 closed this Feb 2, 2015
@drtjmb
Copy link
Member Author

@drtjmb drtjmb commented Feb 3, 2015

@phluid61 - I think it's one of those rules of thumb handed down by the perl monks - my guess is there is no harm in modifying $_ in this case but not a habit you generally want to get into :-) Thanks for making the change.

@UmbrellaDish
Copy link

@UmbrellaDish UmbrellaDish commented Feb 4, 2015

In Perl Best Practices, Damian Conway recommends for loop in this case of in-place modification, reserving map for really trivial read, process and stuff results elsewhere:

for ( @values ) { s/%3A/:/g }

When the loop grows, there is an option to write for my $varname (...) {...}, then you've got a named alias instead of $_.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants